Jump to content


Photo

Need assistance with displaying results of dynamic select list


  • Please log in to reply
3 replies to this topic

#1 drranch

drranch
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 03 August 2006 - 08:13 PM

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*


#2 CTM

CTM
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 03 August 2006 - 08:20 PM

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.

#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 03 August 2006 - 08:57 PM

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"].
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#4 drranch

drranch
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 03 August 2006 - 09:19 PM

;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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users