Can't seem to capture a variable in a chained select
Posted on
16th Feb 2014 07:03 pm by
admin
I'm *this* close to having a chained select running but for some reason it doesn't seem to be picking up a variable.
Code: <?php
require ('inc/connection.php');
//seeming that we are just submitting and refreshing to the one page we need to check if the post variable is set, and if so a couple of other variables are set
if(!isset($_POST['state'])) {
$next_dropdown = 0;
}
else {
//When set this variable reveals the next drop down menu
$next_dropdown = 1;
//this variable keeps the previous selection selected
$selected = $_POST['state'];
}
?>
<form name="form" method="post" action="">
<select name="state" style="font-size:20px;">
<option value="NULL">State</option>
<?php
$query = "SELECT id, name FROM state ORDER BY name ASC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{?>
<option value="<?php echo $row[0]; ?>" onClick="document.form.submit()" <?php if(isset($selected) && $row[0] == $selected) {echo "selected='selected'";} ?>><?php echo $row[1]; ?></option>n";
<?php }
echo '</form>n';
//this is where the other form will appear if the previous form is submitted
if($next_dropdown == 1) {?>
<form name="form2" action="" method="post">
<select name="city">
<option value="NULL">City</option>
<?php
$query2 = "SELECT * FROM city WHERE state_id = " . $row[0];
$result2 = mysql_query($query2);
while($row2 = mysql_fetch_array($result2))
{ ?>
<option value="<?php echo $row2[0]; ?>" onClick="document.form2.submit()"><?php echo $row2[1]; ?></option>
<?php }?>
</select>
</form>
<?php }
?>
The state drop down works fine. Once a state is selected, it will display the city drop down. However, the city drop down never populates. It's as though it forgets what $row[0] is. Any thoughts?
No comments posted yet
Your Answer:
Login to answer
83
35
Other forums
Which practice of iteration through containers is preferred
In the "real world" what kind of loop do most people use to iterate through a container like a vecto
Pagination won't carry results past page 2.
Hi all,
I've worked out my pagination script and its paginating fine until I click next from
Can I call a class inside a function?
I have a class written in another file that handles my image resizing.
Can I do this (php say
TinyMCE / Ajax Postback Problem
Hiya all,
I have a page which loads the TinyMCE editor. On the postback I obviously want to f
Add 5 to a variable when a button is clicked, and re-run a for loop
So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to
Website Direction...
I recently used this code to try and make it so the page loads as http://www.domain.com/ when you ty
opening a window with after form submission
I know this this forum has nothing to do with JS, but i'm trying to use it with my php script.
<
Confused with Loop
guys, i got confused with Looping...this is the case
I have 3 stocks, let say "Stock A&q
Strip Slashes Help
I've got a script that i've downloaded of the net to edit multiple fields from my sql database, and
PHP Script runs on CLI but not through web browser
I am running into an issue that I just can't seem to find the answer to. I have a Windows Server 200