Jump to content

Fill Drop Down Box with Field Names


Petty_Crim

Recommended Posts

I'm having trouble trying to fill a drop down box with the names of fields. Basically I'm making a db for a team and I got various fields including the names of players who might play in it. In my loop I exclude thenone player fields and then add the player fields to a drop down box so I should end up with a drop down box of all the players. My problem is its not working

This is my code I'm using atm:

$result3=mysql_query("SELECT * FROM bf2stats WHERE match_id='$match_idP'");

echo "<td>";
echo "<select name='player_list'>";
echo "<option value='-1'>(Change Player)</option>";
while($fldb = mysql_fetch_field($result3))
{
if ($fldb->name!='match_id' && $fldb->name!='match_name' && $fldb->name!='score' && $fldb->name!='result' && $fldb->name!='date')
    {
		$m=$fldb->name;
		echo "<option value=$m>$m</option>";
    }
}
echo "</select>";
echo "</td>";

 

My table looks similar to this

match_idmatch_name

[/td]score

date John Fred Larry

1Pirates Team3-0Win12/12/2006010

Link to comment
https://forums.phpfreaks.com/topic/57698-fill-drop-down-box-with-field-names/
Share on other sites

check the loop is executing or not?

 

while($fldb = mysql_fetch_field($result3))

{

if ($fldb->name!='match_id' && $fldb->name!='match_name' && $fldb->name!='score' && $fldb->name!='result' && $fldb->name!='date')

    {

echo"im here";

$m=$fldb->name;

echo "<option value=$m>$m</option>";

    }

}

Ok this is weird i made a result called $result7 with exactly the same stuff as $result3 and used that in the loop and presto it works.

 

So now I'm wondering does looping more then once on a query have an effect? In my code I've used $result3 once before in a fetch field thing, so maybe I'm only allowed to do this once?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.