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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 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.