phatgreenbuds Posted January 5, 2007 Share Posted January 5, 2007 First I apologize if this has been asked a thousand times before. If it has please feel free to point me to the link...I searched but could not find anything most likely because I do not know what to search for.I have a simple database that lists names within it. I am trying to get a page with a drop down that will query that table and display the names for selection. Below is what I thought to be right but turns out I am wrong AGAIN. Any ideas?[code]<html><head><title>test</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><div align="center"><table width="50%" border="0" align="center"><tr> <td><SELECT id="id1" name="Name" style="width:150px"> <?PHP $con = mysql_connect ("localhost", "root", "me"); if (!$con) { die('Could Not Connect: ' . mysql_error()); } mysql_select_db ("test", $con); $query="SELECT name FROM users"; $results=mysql_query($query) or die(mysql_error()); while ( $rows = mysql_fetch_array($result) ){ foreach ($rows as $value) { echo '<OPTION value= "'. $row['name'] .'"> '. $row['name'] .' </OPTION>'."\r\n"; } } ?> </SELECT></div></p> </td> <td><form method="post" action="http://localhost/testsite/srepadd.php"> <div align="center"><p>Blah Blah: <br> <input type="text" name="srid"></div></p> </td> </tr></table></form><br></div></html>[/code] Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/ Share on other sites More sharing options...
ikmyer Posted January 5, 2007 Share Posted January 5, 2007 try taking out the [code] foreach ($rows as $value) { [/code] and corresponding [code] } [/code] Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/#findComment-153735 Share on other sites More sharing options...
phatgreenbuds Posted January 5, 2007 Author Share Posted January 5, 2007 just noticed that in there and removed it but the drop down is still blank. Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/#findComment-153738 Share on other sites More sharing options...
kenrbnsn Posted January 5, 2007 Share Posted January 5, 2007 [b]Please[/b] modify your post and replace the [nobbc][color=green][i] and [/i][/color][/nobbc] tags with [nobbc][code][/code][/nobbc] tags. Your code will be much more readable.Ken Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/#findComment-153739 Share on other sites More sharing options...
effigy Posted January 5, 2007 Share Posted January 5, 2007 Change $rows to $row in your while. Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/#findComment-153742 Share on other sites More sharing options...
phatgreenbuds Posted January 5, 2007 Author Share Posted January 5, 2007 ok modified the post sorry...good catch on the $rows I did not see that. However it still did not resolve the issue. Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/#findComment-153744 Share on other sites More sharing options...
phatgreenbuds Posted January 5, 2007 Author Share Posted January 5, 2007 so now it looks like this:[quote] <td><SELECT id="id1" name="Name" style="width:150px"> <?PHP $con = mysql_connect ("localhost", "root", "blaine"); if (!$con) { die('Could Not Connect: ' . mysql_error()); } mysql_select_db ("test", $con); $query="SELECT name FROM users"; $results=mysql_query($query) or die(mysql_error()); while ( $row = mysql_fetch_array($result) ){ echo '<OPTION value= "'. $row['name'] .'"> '. $row['name'] .' </OPTION>'."\r\n"; } ?> </SELECT></div></p> </td>[/quote] Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/#findComment-153749 Share on other sites More sharing options...
effigy Posted January 5, 2007 Share Posted January 5, 2007 Change $result to $results in the while. Heh. Maybe you want to turn on error_reporting for the moment... Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/#findComment-153751 Share on other sites More sharing options...
phatgreenbuds Posted January 5, 2007 Author Share Posted January 5, 2007 OH GOOD GRIEF! Ok I am sorry I am hanging my head in shame. Stupid typo's and not enough sleep. Thank you very much Link to comment https://forums.phpfreaks.com/topic/33014-solved-shed-some-light-on-this-please/#findComment-153756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.