Jump to content

[SOLVED] loading mysql results into a drop down box


blueman378

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.