blueman378 Posted December 4, 2007 Share Posted December 4, 2007 hi guys (and PHP_PhREEEk who is the man) i am trying to get some information from a database and write it to a drop down box, heres the code im using, <?php include("include/session.php"); global $database; $q = "SELECT cName FROM " . gsubcat . " ORDER BY `cName` ASC "; $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 'Cats not found!'; } ?> <form name="cats" action="cats.php"> <select> <?php while( $row = mysql_fetch_assoc($result) ) { echo '<option value="$row[cName];"> echo $row[cName];</option>'; } ?> </select> </form> and heres the result <form name="cats" action="cats.php"> <select> <option value="$row[cName];">echo $row[cName];</option> <option value="$row[cName];">echo $row[cName];</option> <option value="$row[cName];">echo $row[cName];</option> <option value="$row[cName];">echo $row[cName];</option> <option value="$row[cName];">echo $row[cName];</option> <option value="$row[cName];">echo $row[cName];</option> <option value="$row[cName];">echo $row[cName];</option> <option value="$row[cName];">echo $row[cName];</option> </select> </form> obviously not the desired result, i know it is getting the information from the database ok because the amount of options = the information in the database, so any1 help? cheers Link to comment https://forums.phpfreaks.com/topic/80119-solved-loading-mysql-results-into-a-drop-down-box/ Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2007 Share Posted December 4, 2007 you should try something like this while( $row = mysql_fetch_assoc($result) ) { echo "<option value='{$row[cName]}'>{row['cName']}</option>"; } basically you were using single quotes so it was taking the literal string and not as a variable Link to comment https://forums.phpfreaks.com/topic/80119-solved-loading-mysql-results-into-a-drop-down-box/#findComment-406008 Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 <?php while( $row = mysql_fetch_assoc($result) ) { echo '<option value="' . $row['cName'] . '">'; echo $row[cName] . '</option>'; } ?> PhREEEk Link to comment https://forums.phpfreaks.com/topic/80119-solved-loading-mysql-results-into-a-drop-down-box/#findComment-406009 Share on other sites More sharing options...
blueman378 Posted December 4, 2007 Author Share Posted December 4, 2007 ah thanks guys, PHP_PhREEEk's one worked perfectly, rajivgonsalves's one half worked... <form name="cats" action="cats.php"> <select> <option value='Action / Adventure'>{row['cName']}</option> <option value='Beat em up'>{row['cName']}</option> <option value='Other'>{row['cName']}</option> <option value='Puzzle'>{row['cName']}</option> <option value='Racing'>{row['cName']}</option> <option value='Retro'>{row['cName']}</option> <option value='Shoot em up'>{row['cName']}</option> <option value='Sports'>{row['cName']}</option> </select> </form> but its all good thanks peoples hey PHP_PhREEEK how long do u spend on here a day? cheers Link to comment https://forums.phpfreaks.com/topic/80119-solved-loading-mysql-results-into-a-drop-down-box/#findComment-406012 Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 >hey PHP_PhREEEK how long do u spend on here a day? I do try to spend at least 15 mins per day = ^) PhREEEk Link to comment https://forums.phpfreaks.com/topic/80119-solved-loading-mysql-results-into-a-drop-down-box/#findComment-406040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.