Jump to content

Recommended Posts

So here's how I tried it. .

 

$eventname = mysql_fetch_object(mysql_query("SELECT * FROM events ORDER by event_id ASC"));
while($row = mysql_fetch_array($eventname));

 

With

 

			  <tr>
                <td class="subtableheader"><b>Event:</b></td>
                <td class="profilerow"><select name=event><option value=1><?php echo "$row"; ?></option></td>
              </tr>

 

And i get error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in . . .  on line 28

 

Line 28 is the "while($row = mysql. . . )

This is what I got, But it isn't working, If I just echo the results as text, it works, but when i try and do it as a select drop down, it shows none.

 

                <td class="profilerow"><select name=event>      <?
   $select_event = mysql_query("SELECT * FROM events ORDER by id ASC");
   while($the=mysql_fetch_object($select_event)){
   
   }
   echo "<option value=1>$the->event</option>";
   
   
   
   
   ?></td>

Yeah i missed the closing select tag, made no difference though. Here's the HTML source. .

			  <tr>
                <td class="subtableheader"><b>Event:</b></td>
                <td class="profilerow">      <select name=event><option value=1></option></select></td>
              </tr>

 

And I do know that but don't know how I'd change that?

 

Thanks

Your query is either failing, or returning an empty results set. Do you have error reporting set up to display errors to the screen? You also need to verify that your query not only executed, but also returned more than 0 records before attempting to use the data.

<select name="event">      
<?php
$select_event = mysql_query("SELECT id, event FROM events ORDER by id ASC");
while($the=mysql_fetch_object($select_event)){
	echo "<option value=\"" .$the->id . "\">" .$the->event . "</option>\r";
}
?>
</select>

 

You don't want an empty select if there are no options.

<?php
// Define query
$query = mysql_query("SELECT id, event FROM events ORDER by id ASC");

// Ensure you have values returned
if( mysql_num_rows( $query ) >= 1 ) {

// Rows is more than 1, build select menu
$dropdown = '<select name="horse" id="horse_drop">';

// Now build loop
while( $item = mysql_fetch_assoc( $query ) {
	$dropdown .= '<option value="' . $item["value"] . '">' . $item["name"] . '</option>';
}

// Close select menu
$dropdown .= '</select>';
} else {
// Error checking
$dropdown = 'bad horsey!';
?>

// Wherever you want your select menu to be, you simply
echo $dropdown;
</select>

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.