Jump to content

Archived

This topic is now archived and is closed to further replies.

drranch

Need assistance with displaying results of dynamic select list

Recommended Posts

I've had great luck here before so here goes.....another dilemma

I’m so glad you people love doin' this stuff!

I have a dynamic select list that is pulling data from my database, but it’s not able to retrieve results when selecting an item from the dynamic list.

PHP Code:
<?php
mysql_select_db($database_fred, $fred);
$query_cars = "SELECT * FROM cars WHERE username='{$_SESSION[loginUsername]}' ORDER BY car.name";
$cars = mysql_query($query_cars, $fred) or die(mysql_error());
$row_cars = mysql_fetch_assoc($cars);
$totalRows_cars = mysql_num_rows($cars);
?>

Form:
<form name="cars" action="" method="POST" >
<blockquote>
<p>
</p>
<p>
<SELECT name="carlist" size="1" onChange="Javascript:document.cars.submit();">
<?php
do {
?>
<option value="<?php echo $row_cars['name']?>"><?php echo $row_cars['name']?></option>
<?php
} while ($row_cars = mysql_fetch_assoc($cars));
$rows = mysql_num_rows($cars);
if($rows > 0) {
mysql_data_seek($cars, 0);
$row_cars = mysql_fetch_assoc($cars);
}
?>

Do I need another script to retrieve results based on the value selected by the end user?  Right now how it stands is when I select an item from the list my screen does nothing.  I do have the connection set at the top of the PHP file – Thought I would save a lot of unnecessary reading.  Connection works find because I have options to select from.

*sigh*

Share this post


Link to post
Share on other sites
PHP can't do dynamic things :)

What you should do is fetch all the possible results before outputting anything and add them in a Javascript array. Then, through Javascript means, you can switch options dynamically. Forget PHP and Dynamic, unless you're using AJAX.

Share this post


Link to post
Share on other sites
You have not set an action for the form to use when it is submitted. You will need a script to process the result of the selection, and put the name of this script in the action parameter of the opening form tag. The script would access the value of the selection in the variable $_POST["carlist"].

Share this post


Link to post
Share on other sites
;D

Thanks to the KING!

That's what I thought, but I guess I just needed someone to hold my hand as I learn........One step forward again.

And again I have good luck here!

thank you, thank you, thank you

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.