Page 1 of 1

Some help with arrays / displaying results

Posted: Wed Jan 16, 2008 3:05 pm
by chrisjc
I have one page that has a drop down menu, once the user selects the desired option it will then pass the selected value to a 2nd drop down. Once they select there next option I pass that value...
Now I would like to hold the 2nd selected value, have it search the database find all that match the selected and then only display what matches it in the corresponding ROWS in the database.

I have no issue passing one value to another dropdown box thats easy plus I am using ajax could some one help me write an array to HOLD the selected value and then only find the information attached to that value.

Here is the code I was trying. The code starts at the getpart command

Code: Select all

 
// =====================================================================================================
// Construct parts overview after user selected state, city.
// =====================================================================================================
if( (isset($_GET['getpart']) AND isset($_GET['state']) AND isset($_GET['city']))
    OR (isset($_GET['search']) ) ) {
  if(isset($_GET['getpart'])) {  
     $st = $_GET['state']; 
     $ci = $_GET['city']; 
     $query="SELECT dealerlocater.state, ".
            " dealerlocater.company, dealerlocater.address, dealerlocater.city, dealerlocater.stateabb, dealerlocater.zip, dealerlocater.phone, dealerlocater.web ".
            " FROM dealerlocater ".
            " WHERE state='$st' ".
            " GROUP BY dealerlocater.state ".
            " ORDER BY dealerlocater.state ";
  }
$res = mysql_query($query)
  or die("Invalid query: " . mysql_query());
// verify that the part number has been passed
if (!isset($_REQUEST['city']) OR strlen(trim(strip_tags($_REQUEST['city']))) < 4 )
   die("Invalid city specified.");
// sanitize and save the requested part number
$city = trim(strip_tags($_REQUEST['city']));
// select the data row for the specified part number
$res = mysql_query("SELECT * FROM dealerlocater WHERE city='$city' LIMIT 1")
   or die("Invalid select query: " . mysql_query());
// verify that a row has been selected, if not: issue message
if (mysql_num_rows($res) < 1)
   echo "No database information for '$city' found.";
// a row had been selected, process the data
else {
  $row = mysql_fetch_assoc($res);
  $city = $row['city'];
  $st = $row['state'];
  
echo $city;
 
?>
 
If you need the full page 1 code and full page 2 code please let me know.

Re: Some help with arrays / displaying results

Posted: Wed Jan 16, 2008 7:06 pm
by RobertGonzalez
So what you are doing is passing a form POST variable to a script and wanting to use that to query the database?