darkhappy Posted February 16, 2008 Share Posted February 16, 2008 Hi folks, hope you don't mind a newbie question. I have found a lot of posts on this subject but I think on more advanced issues regarding it rather than the basic concept. I have a SQL db with company data (name, street, zip, phone, etc..) and I have a php array that pulls the data from the db and prints out the Company name: $qry = "SELECT * FROM companies"; $result = mysql_query($qry) or die(mysql_error()); $var = "Company Name"; echo "<u>",$var,"</u>"; echo "<br><br>"; while ($r = mysql_fetch_array($result)) { $cname = $r["cname"]; $cstreet = $r["cstreet"]; $cphone = $r["cphone"]; $ccity = $r["ccity"]; $cstate = $r["cstate"]; $czip = $r["czip"]; echo $cname . "<br>"; } What I am trying to do, is put the company name ($cname) in a drop-down list, so that when the company name is selected, all of the other data for that company displays in a table beneath the list. This is a "View company data" screen. I'm really not sure which direction to go in, any advice would be appreciated. Thanks, bobby Link to comment https://forums.phpfreaks.com/topic/91402-creating-drop-down-list-from-sql-data/ Share on other sites More sharing options...
xenophobia Posted February 16, 2008 Share Posted February 16, 2008 <?php $qry = "SELECT * FROM companies"; $result = mysql_query($qry) or die(mysql_error()); $var = "Company Name"; echo "<u>",$var,"</u>"; echo "<br><br>"; ?> <select name="company"> <?php while ($r = mysql_fetch_array($result)) { $cname = $r["cname"]; $cstreet = $r["cstreet"]; $cphone = $r["cphone"]; $ccity = $r["ccity"]; $cstate = $r["cstate"]; $czip = $r["czip"]; ?> <option value="<?php echo $cname; ?>"><?php echo $cname; ?></option> <?php } ?> Nested php script with HTML. Simply but ugly. But you can catch the concept well by doing this. Good luck. Link to comment https://forums.phpfreaks.com/topic/91402-creating-drop-down-list-from-sql-data/#findComment-468375 Share on other sites More sharing options...
darkhappy Posted February 17, 2008 Author Share Posted February 17, 2008 Works great, I could not figure out how to embed the code, thanks dude! Link to comment https://forums.phpfreaks.com/topic/91402-creating-drop-down-list-from-sql-data/#findComment-468800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.