Forum Moderators: coopster

Message Too Old, No Replies

Loading a query from a drop list

         

egibberate

9:36 pm on Dec 20, 2008 (gmt 0)

10+ Year Member



Hi,
beginner question

brief description of what I am trying to achieve;
1. Click dropdown list
2. Select a [card_number] from list
3. Have the corresponding [id] assigned to a variable $myvariable
4. Use that variable in Query "SELECT date, amount FROM spending WHERE card_number = ('$myvariable')"
5. Display the results in a table in the same page

I'm struggling with the syntax (and more!)

I have a dropdown list that offers a choice of card_numbers (card_1, card_2, card_3, card_4)


<?
$query="SELECT id,card_number FROM card_number";
$result = mysql_query ($query);
echo "<select name='car'>
<option value=''>Select One</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[id]>$nt[card_number]</option>";
}
echo "</select>";
?>

Questions;
How do I save the user choice corresponding [id] to $myvariable?
What is the correct method of reloading the page to display the result of the Query
(I would rather just reload the page at this stage in my learning)

Thanks anyone for any advice you are able to give.

egibberate

1:44 am on Dec 21, 2008 (gmt 0)

10+ Year Member



I have the answer to this now but thank you to anyone who read the post & tried to work out the solution.

coopster

1:47 pm on Dec 21, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm guessing you realized the value was passed back to your script in the PHP $_POST superglobal, assuming your html form was using a method="post"

Glad you got it sorted!