ady01 Posted May 3, 2008 Share Posted May 3, 2008 Im creating a drop down menu in PHP which pulls data from a table in MySqL : This is my code > <?php require_once("config.php"); $db=mysql_connect($AddressBook_HOST,$AddressBook_Username,$AddressBook_Password); mysql_select_db($AddressBook_DatabaseName,$db); $query = "SELECT HouseNumber FROM Addresses ORDER BY HouseNumber"; $result = @mysql_query($query); print "<p><select></p>"; if (mysql_num_rows($result) > 0) : while ($row = mysql_fetch_array($result)) : $HouseNumber = $row[HouseNumber]; print "<p><option>value='$HouseNumber'>$HouseNumber</option></p>"; endwhile; print "<p></select></p>"; endif; ?> Its Kind of working but on the web page the option in the dropdown box is showing Value='$HouseNumber'>$HouseNumber instead of the real data ? Any Idears what i've done wrong here ? Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/ Share on other sites More sharing options...
DeFActo Posted May 3, 2008 Share Posted May 3, 2008 print '<p><option value="'$HouseNumber'">'$HouseNumber'</option></p>'; try that. Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532374 Share on other sites More sharing options...
ady01 Posted May 3, 2008 Author Share Posted May 3, 2008 Better, but the dropdown box now just has $'HouseNumber' and under it it says "; endif; ?> Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532377 Share on other sites More sharing options...
DeFActo Posted May 3, 2008 Share Posted May 3, 2008 check this out http://www.phpfreaks.com/forums/index.php/topic,195463.0.html Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532380 Share on other sites More sharing options...
ady01 Posted May 3, 2008 Author Share Posted May 3, 2008 Weird, still not getting a dropdown box now just getting the below in the space where the dropdown should be !! '.$field.''; } ?> Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532396 Share on other sites More sharing options...
DeFActo Posted May 3, 2008 Share Posted May 3, 2008 <?php require_once("config.php"); $db=mysql_connect($AddressBook_HOST,$AddressBook_Username,$AddressBook_Password); mysql_select_db($AddressBook_DatabaseName,$db); $query = "SELECT HouseNumber FROM Addresses ORDER BY HouseNumber"; $result = @mysql_query($query); print "<p><select></p>"; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $HouseNumber = $row[HouseNumber]; print '<p><option value="'.$HouseNumber.'">'.$HouseNumber.'</option></p>'; } print "<p></select></p>"; } ?> what about now? found some mistake, sorry, try now. Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532401 Share on other sites More sharing options...
Xurion Posted May 3, 2008 Share Posted May 3, 2008 Why are you putting P tags around your other elements? Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532409 Share on other sites More sharing options...
ady01 Posted May 3, 2008 Author Share Posted May 3, 2008 Still nothing, the attatched file is what the dropdown box looks like with this code mate : Just cant understand why the word 'housenumber' is appearing instead of the data ! [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532410 Share on other sites More sharing options...
ady01 Posted May 3, 2008 Author Share Posted May 3, 2008 Do you think I should try taking them all off ? If im honest I put them there due to 'thinking' i needed them ? Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532414 Share on other sites More sharing options...
ady01 Posted May 3, 2008 Author Share Posted May 3, 2008 Think they need to be there taking them off just results in the below being shown on the page >>> "; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $HouseNumber = $row[HouseNumber]; print ''.$HouseNumber.''; endwhile} print ""; } ?> Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532418 Share on other sites More sharing options...
blueman378 Posted May 4, 2008 Share Posted May 4, 2008 try something like this, <form action="<?=$PHP_SELF?>" method="post"> <?php global $database; $q = "SELECT HouseNumber FROM Addresses ORDER BY 'HouseNumber' "; $result = $database->query($q) or die("Error: " . mysql_error()); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if( $num_rows == 0 ){ return 'NONE FOUND!'; } ?> <select name="name"> <?php while( $row = mysql_fetch_assoc($result) ) { echo '<option value="' . $row[HouseNumber] . '">'; echo $row[HouseNumber] . '</option>'; } ?> </select> </form> Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532507 Share on other sites More sharing options...
ady01 Posted May 4, 2008 Author Share Posted May 4, 2008 Well Thanks For the 'new way' not sure why all this is not working though still getting the below !!! " method="post"> query($q) or die("Error: " . mysql_error()); $num_rows = mysql_numrows($result); if( $num_rows == 0 ){ return 'NONE FOUND!'; } ?> I have done a whole search database here and cant get a simple drop down working ! Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532827 Share on other sites More sharing options...
ady01 Posted May 4, 2008 Author Share Posted May 4, 2008 *Bump* Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532926 Share on other sites More sharing options...
rarebit Posted May 4, 2008 Share Posted May 4, 2008 Back to your original version: print "<select>"; while ($row = mysql_fetch_array($result)) : $HouseNumber = $row[HouseNumber]; print "<option>value='".$row['HouseNumber']."'>".$row['HouseNumber']."</option>"; } print "</select>"; should work... however if this doesn't, could you show the html code which is outputted! Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532963 Share on other sites More sharing options...
ady01 Posted May 4, 2008 Author Share Posted May 4, 2008 Sure im getting the below when run Value='$HouseNumber'>$HouseNumber I think I will stick with my original code as what blueman is suggesting just makes things worse. Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532971 Share on other sites More sharing options...
rarebit Posted May 4, 2008 Share Posted May 4, 2008 You should be getting something like: <select> <option>value='42'>42</option> <option>value='69'>69</option> </select> oooh, I see it... it actually needs to look like this: <select> <option value='42'>42</option> <option value='69'>69</option> </select> we're closing the tags too soon! Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532975 Share on other sites More sharing options...
ady01 Posted May 4, 2008 Author Share Posted May 4, 2008 Good one ! Think im still missing a trick though as this is a screen shot of what i get (I have also reposted the code as it now stands!!) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <br /> <?php require_once("config.php"); $db=mysql_connect($AddressBook_HOST,$AddressBook_Username,$AddressBook_Password); mysql_select_db($AddressBook_DatabaseName,$db); $query = "SELECT HouseNumber FROM Addresses ORDER BY HouseNumber"; $result = @mysql_query($query); print "<p><select></p>"; if (mysql_num_rows($result) > 0) : while ($row = mysql_fetch_array($result)) : $HouseNumber = $row[HouseNumber]; print "<p><option value='$HouseNumber'>$HouseNumber</option></p>"; endwhile; print "<p></select></p>"; endif; ?> </body> </html> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532985 Share on other sites More sharing options...
rarebit Posted May 4, 2008 Share Posted May 4, 2008 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <br /> <?php require_once("config.php"); $db=mysql_connect($AddressBook_HOST,$AddressBook_Username,$AddressBook_Password); mysql_select_db($AddressBook_DatabaseName,$db); $query = "SELECT HouseNumber FROM Addresses ORDER BY HouseNumber"; $result = @mysql_query($query); print "<p><select>"; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_array($result)) { $HouseNumber = $row[HouseNumber]; print "<option value='$HouseNumber'>$HouseNumber</option>"; } print "</select></p>"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-532993 Share on other sites More sharing options...
MattDunbar Posted May 4, 2008 Share Posted May 4, 2008 Have you tested your PHP installation on this server yet? Make a page phpinfo.php with the contents: <?php phpinfo(); ?> If this code contains a large table of values its the code, if not you don't have PHP setup correctly which is what this looks like to me. Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-533000 Share on other sites More sharing options...
ady01 Posted May 4, 2008 Author Share Posted May 4, 2008 Yes everything else working fine just not this Dam drop down menu !!! Sorry Rarebit, still same Problem ! Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-533009 Share on other sites More sharing options...
MattDunbar Posted May 4, 2008 Share Posted May 4, 2008 print "<option value='$HouseNumber'>$HouseNumber</option>"; Replace that with: print '<option value="'.$HouseNumber.'">'.$HouseNumber.'</option>'; Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-533013 Share on other sites More sharing options...
ady01 Posted May 4, 2008 Author Share Posted May 4, 2008 Still the same mate, im wondering if ORDERBY HouseNumber is the problem here, I know it shouldent be but something is telling me that i should maybe try ordering by ID or something (E.g taking data from HouseNumber and then order by ID number) That make any sence ? Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-533025 Share on other sites More sharing options...
MattDunbar Posted May 4, 2008 Share Posted May 4, 2008 Well, then I guess you're going to need to get to more difficult debugging. Try adding things such as echoing mysql_num_rows($result) check that it is grabbing the right data. Tell me if that returns the correct number of rows. Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-533027 Share on other sites More sharing options...
ady01 Posted May 5, 2008 Author Share Posted May 5, 2008 *bump* Link to comment https://forums.phpfreaks.com/topic/103990-drop-down-menu-not-working/#findComment-533780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.