Jump to content


Photo

Mysql syntax


  • Please log in to reply
2 replies to this topic

#1 Alanmoss

Alanmoss
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 29 May 2006 - 12:09 PM

I'am trying to populate a drop down list from my date base
The drop down list shows the correct number of entrys from the table
but they are blank on the drop down list.

What have I done wrong . I think its a simple syntax error but I just can't see it.

Help please.

Here's the code:
echo '<div align="center">
<form method="get" action="users_online.php">
<select name="type">
<option value="">Choose a Category:</option>
';

// Retrieve and display the available categories.
$query = 'SELECT * FROM currency ORDER BY currency_id';
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {

//this line is the problem

    echo '<option value="'.$row['exchange_rate'].'">'.$row['country_name'].'</option>';
}

// Complete the form.
echo '</select>
<input type="submit" name="submit" value="Go!">
</form>
</div>';
if(isset($_POST['type']))
    {
        $name = $_POST['type'];
echo'<p>'.$name.'</p>';
}


#2 Randy

Randy
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationNewcastle, UK

Posted 29 May 2006 - 02:12 PM

try changing MYSQL_NUM to MYSQL_ASSOC

MYSQL_NUM returns an array like: [0] -> Hello [1] -> Hi
whereas MYSQL_ASSOC returns an array like: [Money] -> 12 [Tax] -> 17.5

you can refer to a MYSQL_ASSOC array with $array['tax'] which is what you seem to be using

#3 Alanmoss

Alanmoss
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 29 May 2006 - 02:57 PM

[!--quoteo(post=378067:date=May 29 2006, 02:12 PM:name=Randy)--][div class=\'quotetop\']QUOTE(Randy @ May 29 2006, 02:12 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
try changing MYSQL_NUM to MYSQL_ASSOC

MYSQL_NUM returns an array like: [0] -> Hello [1] -> Hi
whereas MYSQL_ASSOC returns an array like: [Money] -> 12 [Tax] -> 17.5

you can refer to a MYSQL_ASSOC array with $array['tax'] which is what you seem to be using
[/quote]


Thanks Very Much it works.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users