jasonxxx102 Posted February 7, 2014 Share Posted February 7, 2014 Ok, so I have a main page that grabs data from a MySQL db and posts it into a dropdown menu see here: $sql = "SELECT * FROM 4000Series"; $result = $con->query($sql); print "Select your GPU: <select name='gpuId'>"; while ($row = $result->fetch_assoc()) { print "<option value='" .$row["id"] . "'>" . $row["gpu"] . "</option>"; } print "</select> </br>\n"; This works fine, from here I'm passing the POST data from the option values to a new page (basically the option values correspond directly to the "id" value in my SQL db). The values are passed onto the new page fine, but when I try to setup an SQL select statement to grab the row with the corresponding "id" value and print it out with a while loop I'm shooting a blank. Here's the code for the second page $id = $_POST['gpuId']; **Connect to sql db here** $sql = "SELECT * FROM 4000Series WHERE $id ='id'"; $result = $con->query($sql); echo "<table>"; while ($row = $result->fetch_assoc()){ echo "<tr><td>" . $row['id'] . "</td><td>" . $row['gpu'] . "</td></tr>"; } echo "</table>"; When I view the source it prints out the table tags but nothing in the while loop, any ideas? Link to comment https://forums.phpfreaks.com/topic/286028-loop-through-sql-results-to-print-an-html-table/ Share on other sites More sharing options...
denno020 Posted February 7, 2014 Share Posted February 7, 2014 Don't you have to call execute() on $con? I don't know what $con is so I don't know what method you're using.. Link to comment https://forums.phpfreaks.com/topic/286028-loop-through-sql-results-to-print-an-html-table/#findComment-1468110 Share on other sites More sharing options...
mac_gyver Posted February 7, 2014 Share Posted February 7, 2014 you have a $ in front of your id column name in your query, you are also missing the $ in front of the $id variable name in your query OR you could remove the single-quotes from around the id column name in your query. if you include a debugging step where you echo out your sql query statement, you would have likely seen this problem. Link to comment https://forums.phpfreaks.com/topic/286028-loop-through-sql-results-to-print-an-html-table/#findComment-1468111 Share on other sites More sharing options...
jasonxxx102 Posted February 8, 2014 Author Share Posted February 8, 2014 Thanks mac_gyver! your help was much appreciated Link to comment https://forums.phpfreaks.com/topic/286028-loop-through-sql-results-to-print-an-html-table/#findComment-1468186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.