getting id's from drop down lists

I have a mysql database which has a table holding football team names and another table for setting up schedules. I am using a drop down list to pick the teams (a home team and an away team), so I’m using the same script twice on the page. I can retrieve the first team_id and post it in the database, but I don’t know how to get the 2nd team_id, so I can post them both at the same time from the same page.
This is the code that I’m using twice on the page (www.beat-the-spread.net/admin_editschedule.php).
The code is already placed in the .

<?php include("opendatabase.php"); $querya="SELECT team_id,team_name FROM teams"; $resulta = mysql_query ($querya); echo ""; while($hometeam=mysql_fetch_array($resulta)) { echo "$hometeam[team_name]"; } echo ""; ?>

I understand that “team_name” will return the team_id, but how do I assign different names so I can insert 2 separate id’s into the database? Hope that makes sense.

Thanks for any help!

simple,

  1. In the line that has “<select name=…” user the name as ‘team_name_1’ instead of ‘team_name’
  2. Copy the same drop down box generation script for the second team and name it as ‘team_name_2’
  3. When the form is submitted you will have two variables in the post data i.e, $_POST[‘team_name_1’] (first team id) and $_POST[‘team_name_2’] (second team id).
  4. You can use those two variables to store separately in the table.

The drop down box script looks like

[php]

<?php include("opendatabase.php"); $querya="SELECT team_id,team_name FROM teams"; $resulta = mysql_query ($querya); echo ""; while($hometeam=mysql_fetch_array($resulta)) { echo "$hometeam[team_name]"; } echo ""; echo ""; // second team drop down box generation while($hometeam=mysql_fetch_array($resulta)) { echo "$hometeam[team_name]"; } echo ""; ?>

[/php]

Hope it makes sense :slight_smile:

Thanks, byraja.
I figured it was that simple, but I was caught up in trying to produce an array with team_name[].
Anyway, it works fine now. Appreciate it!

you are welcome, glad it helped.

Besides, it also works well with array. If you name both the drop down boxes with ‘team_name’, then it submits both the data items as array items of team_name. you can access them with the indexes as follows

$team_name[0] - first team id
$team_name[1] - second team id

P.S : I haven’t really tried it, i think it works, u can give it a try… :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service