Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing variables from a drop down select 1

Status
Not open for further replies.

solfer

Programmer
Jan 17, 2002
7
0
0
GB
I've managed to populate a drop down select with 2 fields from my db...

<?
$connection = mysql_connect(&quot;aaa&quot;,&quot;bbb&quot;,&quot;ccc&quot;)
or die(&quot;Couldn't make connection.&quot;);

$db = mysql_select_db(&quot;ddd&quot;, $connection)
or die(&quot;Couldn't select database.&quot;);

$sql = &quot;SELECT * FROM fixtures ORDER BY date ASC&quot;;

$sql_result = mysql_query($sql,$connection)
or die(&quot;Couldn't execute query.&quot;);

// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {
$team = $row[&quot;team&quot;];
$date = $row[&quot;date&quot;];
$option_block .= &quot;<OPTION value=\&quot;$team $date\&quot;>$team - $date</OPTION>&quot;;

}

?>

<FORM method=&quot;POST&quot; action=&quot;newpage.php&quot;>
<P>Fixture:<br>
<SELECT name=&quot;fixture&quot; class=&quot;formbox&quot;>
<? echo &quot;$option_block&quot;; ?>
</SELECT>

<P><INPUT type=&quot;submit&quot; value=&quot;submit&quot;></p>
</FORM>


I'm presuming that $fixture gets passed to newpage.php as the string value of '$team $date'?

I need newpage.php to re query my db and select the record where the team and date matches that selected from the previous page... help, my head hurts and as you've probably guessed, I'm not to hot at this stuff!!

TIA
Solfer
 
I assume your <option> tags appear inside a set of <select> tags, and that the <select> tag has the attribute &quot;name&quot; set. If so, the form will return the selected option in the variable that matches the name of the <select> tag.

I would suggest two variations to what you have already done.

If you have some kind of index on each row of your table, I would suggest setting your option values to that index instead of date+team. The return value from the select will then have a single value, which is the index matching the row.

If your table does not have an index, I would suggest using a separator between the date and team name. It would make it easier to break apart the two combined values once the form is submitted.


In either case, from that point you should know what to do. Use the returned values in a WHERE clause of another SELECT statment to your database. ______________________________________________________________________
Did you know?
The quality of our answers is directly proportional to the number of stars you vote?
 
Bingo! Used my index & all's working fine now - thx sleipnir214, you're a star!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top