Jump to content

Some help with Drop down box


Shadowing

Recommended Posts

trying to get my drop down box to display more then one result. I have two users with Mod wrote in the column Monitor

but right now it only displays just the one.

So I need to display all the goaulds that have mod in the monitor column

 

<?php

			
                                          $result = mysql_query("SELECT goauld FROM users WHERE monitor ='mod' ORDER BY id DESC") or die(mysql_error());
                                         	
while($row = mysql_fetch_array( $result )) {

                           if($row['goauld'] == $_POST['name_list']){

echo '<div class="containerc">';
echo '<div class="search">';
echo '<form method="post" >';

echo '<select name="name_list" class="textbox" id="name_list">';

echo "<option value=\"".$row['goauld']."\">".$row['goauld']."</option>";

echo "<option selected=\"selected\" value=\"".$row['goauld']."\">".$row['goauld']."</option>";

echo '</select>';

echo  '<input type="submit" name="remove" id="remove" value="Remove">';

	}
}
}
'</form>';

'</div>';
'</div>';
?> 

Link to comment
Share on other sites

First, <select> doesn't use selected.  You normally identify what is selected by making that the first entry.

 

You are better off collecting all of the values into an array so you can then use that to find what you need.

 

Untested...

 

<?php ...
            
$result = mysql_query("SELECT goauld FROM users WHERE monitor ='mod' 
    ORDER BY id DESC") or die(mysql_error());

$mods = array();
while($raw = mysql_fetch_array( $result )) {
    $mods[] = $raw;
}

echo '<div class="containerc"><div class="search">
    <form method="post" >
    <select name="name_list" class="textbox" id="name_list">';

// First output the mod if they are in the post value and found in the data
foreach($mods as $key => $value) {
    if ($value['goauld'] == $_POST['name_list'] ) {
        echo '<option value="' . $value['goauld'] . '"> ' . $value['goauld'] . '</options>';
    }
}   

// Next list the rest of them omitting the selected selected one
foreach($mods as $key => $value) {
    if ($value['goauld'] != $_POST['name_list'] ) {
        echo '<option value="' . $value['goauld'] . '"> ' . $value['goauld'] . '</options>';
    }
}                           

echo '</select>
    <input type="submit" name="remove" id="remove" value="Remove">
    </form>';

 

 

 

 

Link to comment
Share on other sites

thanks alot dweeber really appreciate it

 

that works great

 

i have a hard time with arrays but ive only been doing this for 3 weeks now lol. so hopefully i'll get to the point of comphrending them well.

 

I like your quote btw

 

This drop down box is to select someone to remove them and I notice when I hit remove it doesnt update the list. Anyway to fix that?

Link to comment
Share on other sites

foreach($mods as $key => $value) {

    if ($value['goauld'] == $_POST['name_list'] ) {

        echo '<option value="' . $value['goauld'] . '" selected="selected"> ' . $value['goauld'] . '</options>';

  }

else{

echo '<option value="' . $value['goauld'] . '"> ' . $value['goauld'] . '</options>';

}

}

Link to comment
Share on other sites

  • 2 weeks later...
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.