Search code examples
phpmysqlibm-cloudcleardb

passing variable to another page for sql query


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();
                    ?>

Solution

  • 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>';