Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying Data
    text
    copied!<p>I have a drop down list which is populated from a MYSQLi query. I want the user to select an option and the values/record associated pulled from the database and displayed to the user based upon FirstName.</p> <p>my table does not have an id column (I didnt make any. Starts with FirstName)</p> <p>It displays the table with column titles but it does not fetch the data dynamically from the db which happens to be coded in the while loop in [view code] below. <strong>I've spent my whole day and whole night trying to figure this out. Help :(</strong> </p> <p><strong>list code</strong></p> <pre><code>&lt;!DOCTYPE&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Update Data&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="form_update" method="post" action="update_test.php"&gt; &lt;?php $con=mysqli_connect("localhost","root","","ismat_db"); //============== check connection if(mysqli_errno($con)) { echo "Can't Connect to mySQL:".mysqli_connect_error(); } else { echo "Connected to mySQL&lt;/br&gt;"; } //This creates the drop down box echo "&lt;select name= 'FirstName'&gt;"; echo '&lt;option value=""&gt;'.'--- Please Select Person ---'.'&lt;/option&gt;'; //$query=mysqli_query($con,"SELECT id,FirstName FROM persons"); $query = mysqli_query($con,"SELECT FirstName FROM persons"); //$query_display = mysqli_query($con,"SELECT * FROM persons"); while($row=mysqli_fetch_array($query)) { echo "&lt;option value='". $row['id']."'&gt;".$row['FirstName'] .'&lt;/option&gt;'; } echo '&lt;/select&gt;'; ?&gt; &lt;input type="submit" name="submit" value="Submit"/&gt; &lt;/form&gt; &lt;br/&gt;&lt;br/&gt; &lt;a href="main.html"&gt; Go back to Main Page &lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>View Code</strong></p> <pre><code>&lt;!DOCTYPE&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Update Data&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php $con=mysqli_connect("localhost","root","","ismat_db"); if(mysqli_errno($con)) { echo "Can't Connect to mySQL:".mysqli_connect_error(); } if(isset($_POST['FirstName'])) { $name = $_POST['FirstName']; $fetch="SELECT Firstname FROM persons WHERE Firstname = '".$name."'"; $result = mysqli_query($con,$fetch); if(!$result) { echo "Error:".(mysqli_error($con)); } //display the table echo '&lt;table border="1"&gt;'.'&lt;tr&gt;'.'&lt;td align="center"&gt;'. 'From Database'. '&lt;/td&gt;'.'&lt;/tr&gt;'; echo '&lt;tr&gt;'.'&lt;td&gt;'.'&lt;table border="1"&gt;'.'&lt;tr&gt;'.'&lt;td&gt;'.'First Name'.'&lt;/td&gt;'.'&lt;td&gt;'.' LastName'.'&lt;/td&gt;'.'&lt;td&gt;'. 'Gender' .'&lt;/td&gt;'.'&lt;td&gt;'. 'Subject'. '&lt;/td&gt;'.'&lt;td&gt;'.' Hobbies' .'&lt;/td&gt;'.'&lt;/tr&gt;'; //Supposed to collect data from db-I tried using _array,_assoc instead of _row //and got mysqli_result() // requires one parameter given boolean while($data=mysqli_fetch_row($result)) { echo ("&lt;tr&gt;&lt;td&gt;$data[0]&lt;/td&gt;&lt;td&gt;$data[1]&lt;/td&gt;&lt;td&gt;$data[2]&lt;/td&gt;&lt;td&gt;$data[3]&lt;/td&gt; &lt;td&gt;$data[4] &lt;/td&gt;&lt;/tr&gt;"); } echo '&lt;/table&gt;'.'&lt;/td&gt;'.'&lt;/tr&gt;'.'&lt;/table&gt;'; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload