Page 1 of 1

Drop Down Lists

Posted: Tue Feb 15, 2011 12:27 pm
by BelowZero
I found a script which creates a nice drop down list from a mysql database (a list of football teams). What I want to do is select a team by name, then insert the team_id into a "reference" field in another table.
Once a team is selected, how do I return just the team_id?

----drop down list code----

Code: Select all

<?php
include("opendatabase.php");

$querya="SELECT team_id,team_name FROM teams";

$resulta = mysql_query ($querya);

echo "<select team_name=option value=''></option>";

while($hometeam=mysql_fetch_array($resulta))
{
echo "<option value=$hometeam[team_id]>$hometeam[team_name]</option>";
}

echo "</select>";
?>
----end code----

I want to create a variable ($hometeam) that is just the team_id number so I can pass it to my insert.php file.
Thanks for helping a newbie!!

Re: Drop Down Lists

Posted: Tue Feb 15, 2011 1:22 pm
by AbraCadaver
You need a form around that with a submit button that submits to insert.php. Also the select should look more like this:

Code: Select all

echo "<select name=\"team_name\"></option>";
Then when you press the submit button the id will be available in $_POST['team_name'].

Re: Drop Down Lists

Posted: Tue Feb 15, 2011 5:48 pm
by BelowZero
Thanks for the reply. Got it working as expected.

Now for part 2:
Can I use this drop down list twice on the same page and assign different values to the 2 choices? I'm trying to choose a home team and an away team to put in the database, both from the same page.

http://www.beat-the-spread.net/admin_editschedule.php

I guess I need a way to pick 2 team_id's and assign them different names so I can post them both to the database at the same time.

Thanks for helping me out.