Some help with arrays / displaying results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chrisjc
Forum Newbie
Posts: 1
Joined: Wed Jan 16, 2008 3:04 pm

Some help with arrays / displaying results

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Some help with arrays / displaying results

Post 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?
Post Reply