2

I am trying to pass a variable from a page to another page so that i can display more information on the other page by getting the idea. I am not really sure what is going wrong and because I use bluemix it doesn`t display an error it just gives me the page 500 error. Here is my code:

<?php
     $strsql = "select id, name, problem, urgency, technology from idea WHERE status='saved'";
    if ($result = $mysqli->query($strsql)) {
       // printf("<br>Select returned %d rows.\n", $result->num_rows);
    } else {
            //Could be many reasons, but most likely the table isn't created yet. init.php will create the table.
            echo "<b>Can't query the database, did you <a href = init.php>Create the table</a> yet?</b>";
        }

      ?>


  <?php
                        echo "<tr>\n";
                        while ($property = mysqli_fetch_field($result)) {
                                echo '<th>' .  $property->name . "</th>\n"; //the headings

                        }
                        echo "</tr>\n";

                         while ( $row = mysqli_fetch_row ( $result ) ) {
                            $idea_id= $row['id'];
                            echo "<tr>\n";
                            for($i = 0; $i < mysqli_num_fields ( $result ); $i ++) {
                              echo <a href ="meerinfo.php?idea= '. $idea_id .'">  '<td>' . "$row[$i]" . '</td>'</a>;
                            }
                            echo "</tr>\n";
                        }


                        $result->close();
                        mysqli_close();
                    ?>
user3356007
  • 393
  • 1
  • 6
  • 20

1 Answers1

2

There's a small bug in your code. Your echo <a href ="... line should be like this,

echo '<td><a href ="meerinfo.php?idea='. $idea_id .'">' . $row[$i] . '</a></td>';
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37
  • The error isn`t showing up anymore Rajdeep but the row is not a link? – user3356007 Dec 28 '15 at 09:47
  • @user3356007 Which row? Are you talking about `$row[$i]`? – Rajdeep Paul Dec 28 '15 at 09:50
  • yes i want the row to send the id to the next page moreinfo but the row isn`t a link now – user3356007 Dec 28 '15 at 09:52
  • The row show all the information i requested on the database and it ads a new row for every new ID that is working fine but i want to make the row clickable and send the id with it so i can use the id for a new query on the other page and display all the information – user3356007 Dec 28 '15 at 10:01
  • it is working now it is a link but it isn`t passing any ID to the other page so there is someting from with putting the id in the variable $idea_id – user3356007 Dec 28 '15 at 10:16
  • @user3356007 So the `$idea_id` is not showing up in the links, right? – Rajdeep Paul Dec 28 '15 at 10:28
  • @user3356007 The problem is you're fetching the result row as an enumerated array, so you can't use `$row['id'];` to get the id of the row. Change `$idea_id= $row['id'];` to `$idea_id= $row[0];`. As a **sidenote**, don't mix procedural and object oriented style of `mysqli`. – Rajdeep Paul Dec 28 '15 at 10:36