Jump to content

Need assistance with displaying results of dynamic select list


drranch

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*
Link to comment
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.
Link to comment
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"].
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.