Forum Moderators: coopster
How do I achieve this? I have the code for the both tables. How do I connect this to the button?
Table1:
<select name ="ID_Number">
<? php
$connection = mysql_connect($_host, $db_user, $db_password) or die("Unable to connect");
mysql_select_db($db_name, $connection);
$query = "SELECT * FROM num_Table1";
$result = mysql_query($query);
while ($record = mysql_fetch_assoc($result))
{
echo "<OPTION VALUE = '".$record["num"]."'>".$record["num"];
}
?>
</select>
Table2:
<? php
$connection = mysql_connect($_host, $db_user, $db_password) or die("Unable to connect");
mysql_select_db($db_name, $connection);
$query = "SELECT * FROM num_Table2";
$result = mysql_query($query);
while ($record = mysql_fetch_assoc($result))
{
echo "<OPTION VALUE = '".$record["num"]."'>".$record["num"];
}
?>
Thanks to everyone for their inputs.
If that's the case you can use an if() [php.net] statement to check which button was pressed and use your database access code appropriately.
<?php
if($_POST[table_1])
{
// Use first code sample
}
elseif($_POST[table_2]
{
// use second code sample
}
else
{
// Display the two buttons for the first page
}
?>
This assumes that your buttons are named "table_1" and "table_2" and you use a form that posts to itself.
Sorry for any confusion. What I was trying to do is to get the select box to have numbers. The select box is already defined in the form and just needed to populate with numbers from the table. I have other fields in the form, after I entered data in these fields I then want to select a number from the select box depending on the table button I pressed.
Does that make sense?
The suggestion you gave me will work but that means the whole form has to be refreshed, instead of refreshing the whole form just want to populate the select box with either numbers from table1 or table2.
Any suggestions?
How do I link Java script to a button and
On click Table1 button how to populate the select tag?
<select name ="Table1"> </Select>
thanks
[edited by: Atomic_Guy at 11:01 am (utc) on Nov. 25, 2006]
[quirksmode.org...]
it's a step by step explanation of how to do that.
If it didn't help you, then write, and we'll try to find sth out.
Michal