CEinNYC Posted December 3, 2010 Share Posted December 3, 2010 Hey all - I (think) that I'm following the code exactly, but no luck... Essentially I want to populate a drop down menu from text stored in mysql (varchar). Here is my code (and where I'm pulling the code found below). Any ideas what's going wrong. (My error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in....). $sql = "SELECT * FROM table"; $results = mysql_query($sql); //or die("Query failed with error: ".mysql_error()); // execute the query $options=""; while ($row=mysql_fetch_array($results)){ $id=$row["id"]; $thing=$row["thing"]; $options.="<OPTION VALUE=\"$id\">".$thing; } <select name="id" style="font-size:20px;font-family:Arial;width:275px"> <option value=0>Choose<? echo $options?></option> </select> Here is where I'm getting my code sample: http://forums.devarticles.com/mysql-development-50/drop-down-menu-populated-from-a-mysql-database-1811.html Thank for any advice!! Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 3, 2010 Share Posted December 3, 2010 Your query is failing - uncomment the "or die()" code to find out what the db error is. Quote Link to comment Share on other sites More sharing options...
OldWest Posted December 3, 2010 Share Posted December 3, 2010 is your table really named "table"? Quote Link to comment Share on other sites More sharing options...
CEinNYC Posted December 3, 2010 Author Share Posted December 3, 2010 Yeah, Noob here. I changed the name wondering if there is a problem with, well, anything. (Throwing it all at the wall and seeing what sticks). here is the remaining part of the error when I uncomment out "or die", Query failed with error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table' at line 1 line 1 can be one of the following: <?php //require 'header.php'; //require 'footer.php'; mysql_connect('localhost', 'root', ''); //username and password of database mysql_select_db('giantbattlemonsters') or die( "Unable to select database"); //$sql = "SELECT id, display_name * FROM table"; $sql = "SELECT * FROM table"; Quote Link to comment Share on other sites More sharing options...
CEinNYC Posted December 3, 2010 Author Share Posted December 3, 2010 I think that I'm narrowing down the problem. I fixed the connection to the database and no longer get any errors with the connection, or line one. however the drop down box is still not populating from the mysql database. I think that I narrowed it down to this bit: while ($row=mysql_fetch_array($results)){ $id=$row["something"]; $thing=$row["id"]; $options.="<OPTION VALUE=\"$id\">".$thing; } When "something" is a row name in the database, I get no errors (but no drop down populating correctly). (using "something" for the sake of indicating the error) So, I need know what's happening there.. "ID" - the ID in the database equals the row (in the database), "something" is.... the row name? (but that doesn't populate the drop down? Thanks for the help! Essentially for a class I'm trying to build a poor mans: http://thesurrealist.co.uk/monster Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.