husin Posted July 19, 2009 Share Posted July 19, 2009 helloe, i have tried like a 5 other ways of populating my dropdown but nothing seems to work. can u guys try and see what's wrong or just give code that works! thank you! ill show u my code: --- <?php require("myConnectionInfo.php"); $Query = "select dlname, dfname from donor order by ascending;" $result=mysql_query($Query); echo '<select name="list">'; while($rec=mysql_fetch_array($result)) { echo '<option value="' . $rect['dlname'] . '">' . $rec['dfname'] . '</option>'; } echo '</select>'; ?> <html> <head></head> <body> <SELECT NAME=list><OPTION VALUE=0>Choose<?=$options?></SELECT> <body> </html> --- Link to comment https://forums.phpfreaks.com/topic/166506-solved-my-drop-down-box-wont-populate-sql/ Share on other sites More sharing options...
mmarif4u Posted July 19, 2009 Share Posted July 19, 2009 What error you get? Link to comment https://forums.phpfreaks.com/topic/166506-solved-my-drop-down-box-wont-populate-sql/#findComment-878039 Share on other sites More sharing options...
stelthius Posted July 19, 2009 Share Posted July 19, 2009 Try this but givei t something to order by... <?php require_once("myConnectionInfo.php"); $query = "SELECT * FROM donor ORDER BY (What do you want to order it by ?) ASC") $result=mysql_query($query); echo '<select name="list">'; while($rec=mysql_fetch_array($result)) { echo '<option value="' . $rect['dlname'] . '">' . $rec['dfname'] . '</option>'; } echo '</select>'; ?> <html> <head></head> <body> <SELECT NAME=list><OPTION VALUE=0>Choose<?=$options?></SELECT> <body> </html> Link to comment https://forums.phpfreaks.com/topic/166506-solved-my-drop-down-box-wont-populate-sql/#findComment-878040 Share on other sites More sharing options...
husin Posted July 20, 2009 Author Share Posted July 20, 2009 alright, i tried what u said, but nothing. oh and i realized i a "t" after one of the $rec, but still did nothing. no errors, just the dropdown won't populate. and i checked my sql stuff, it's fine. any ideas? here's my coding again. changed the query a bit, but that has no effects to why it's not working. <?php require("myConnectionInfo.php"); $query = "select concat (dlname, ", ", dfname) as "Donors" from donor order by dlname;;") $result=mysql_query($query); echo '<select name="list">'; while($rec=mysql_fetch_array($result)) { echo '<option value="' . $rec['dlname'] . '">' . $rec['dfname'] . '</option>'; } echo '</select>'; ?> <html> <head></head> <body> <SELECT NAME=list><OPTION VALUE=0>Donors<?=$options?></SELECT> <body> </html> Link to comment https://forums.phpfreaks.com/topic/166506-solved-my-drop-down-box-wont-populate-sql/#findComment-878375 Share on other sites More sharing options...
Amtran Posted July 20, 2009 Share Posted July 20, 2009 Well, first, why are you echoing the drop down box, and then making another of an identical name below? Get rid of that. Second, try just echoing out the MySQL result, to make sure your query and connection is correct. Link to comment https://forums.phpfreaks.com/topic/166506-solved-my-drop-down-box-wont-populate-sql/#findComment-878430 Share on other sites More sharing options...
husin Posted July 22, 2009 Author Share Posted July 22, 2009 RESOLVED--thanks for tryn guys. my teacher helped me out it was actaully very simple! here's my code. it's a little different though than what i had before: //----// <?php //to avoid the caching of the page header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 01 Jan 1900 00:00:00 GMT"); header("Pragma: no-cache"); require("connection.php"); $query = "select * from donor order by dlname;"; $result=mysql_query($query); $selectBox = "<select id='donorID' name = 'donor' onchange='getDonations();'><option>Click Me</option>"; while($rec=mysql_fetch_array($result)) { $selectBox = $selectBox."<option = $rec[donorNo]>$rec[dlname] $rec[dfname]</option>"; } $selectBox = $selectBox."</select>"; ?> <html> <head> <script type="text/javascript"> function getDonations() { var donorID = "donorID=" + document.getElementById('donorID').value; var myHTTP = new XMLHttpRequest(); myHTTP.open("GET", "table.php", false); myHTTP.send(null); var response = myHTTP.responseText; document.getElementById("tableResults").innerHTML = myHTTP.responseText; } </script> </head> <body> <label>Select Donor: </label><?php echo $selectBox?> <div id='tableResults'></div> <body> </html> //----// Link to comment https://forums.phpfreaks.com/topic/166506-solved-my-drop-down-box-wont-populate-sql/#findComment-880689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.