ziqa Posted March 29, 2012 Share Posted March 29, 2012 helo i a newbie in php. i need some help regarding my system. i want my data from database to display in drop down menu form.anyone have idea how to do that? i really need some help. i have search all over and couldn't find any solution. any suggestions would be helpful Quote Link to comment Share on other sites More sharing options...
abrahamgarcia27 Posted March 29, 2012 Share Posted March 29, 2012 Is this what you are looking for? <?php // Make a MySQL Connection mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM example") or die(mysql_error()); ?> <select name="" > <?php while($record = mysql_fetch_array( $result )) { ?> <option value="<?php echo $record[class_id];?>"><?php echo $record['class_title']; ?> </option> <?php } ?> </select> Quote Link to comment Share on other sites More sharing options...
ziqa Posted March 29, 2012 Author Share Posted March 29, 2012 may i ask what does class_id and class_title stand for? it is the table column? Quote Link to comment Share on other sites More sharing options...
abrahamgarcia27 Posted March 29, 2012 Share Posted March 29, 2012 yeah sorry for that is from one of my past code that i done. The Option Value is what your are actually posting in my case is the class_id and the other is what it is actually displaying in the drop down class_title. So just replace that with your table information. Quote Link to comment Share on other sites More sharing options...
ziqa Posted March 29, 2012 Author Share Posted March 29, 2012 in my table i got 5 columns. can this still be done if i only one to display data only from one of the column in that table? Quote Link to comment Share on other sites More sharing options...
abrahamgarcia27 Posted March 29, 2012 Share Posted March 29, 2012 yeah of course just put the value in both the value and name field of the select. what is this drop down purpose? Quote Link to comment Share on other sites More sharing options...
ziqa Posted March 29, 2012 Author Share Posted March 29, 2012 i got this table for vehicle. so i'm using this drop down menu to display the vehicle no from the vehicle table. this drop down will also change if data in database change right? Quote Link to comment Share on other sites More sharing options...
abrahamgarcia27 Posted March 29, 2012 Share Posted March 29, 2012 yeah it queries the data from your database Quote Link to comment Share on other sites More sharing options...
ziqa Posted March 29, 2012 Author Share Posted March 29, 2012 i don't really get this. the class_title represent my column in database right? then what does class_id stand for? sorry i'm totally new in this Quote Link to comment Share on other sites More sharing options...
ziqa Posted March 29, 2012 Author Share Posted March 29, 2012 sorry.i already solved that problem. my fault. thanks a lot for the help 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.