Jump to content

Passing selected value from PHP menu to MySQL query.


atl_andy

Recommended Posts

I need to pass the value selected from this dropdown....

 

<select name="partnumber" onchange="ajaxFunction('LBox2', this.value);">
<?php
     $dbPN = mysql_connect('localhost','user','pass');
     mysql_select_db('system',$dbPN);

     $resultPN = mysql_query("SELECT record_id, partnumber FROM partnumber");

     while($rowPN = mysql_fetch_array($resultPN, MYSQL_ASSOC))
     {
          echo '<option>'.$rowPN['partnumber'].'</option>';
     }

     mysql_close($dbPN);
?>
</select>

 

To the select statement that populates this dropdown....

 

<?php
     $dbMFR = mysql_connect('localhost','user','pass');
     mysql_select_db('system',$dbMFR);

     $resultMFR = mysql_query("SELECT record_id, manufacturer FROM partnumber WHERE partnumber = 'this.value' ");  // Return the value of the first dropdown here.  The page reloads when the first value is selected.

     while($rowMFR = mysql_fetch_array($resultPN, MYSQL_ASSOC))
     {
          $NewData .= '<option>'.$rowMFR['manufacturer'].'</option>';
     }

     mysql_close($dbMFR);
?>

 

How is this best accomplished?  Is there a way to put the selected value of the first dropdown into a variable after the page reloads?

Figured it out...

 

$selected = $_GET['Param'];

 

then passed that to the second dropdown query:

 

$resultMFR = mysql_query("SELECT record_id, manufacturer FROM partnumber WHERE partnumber = '".$selected."; "); 

 

 

solution found as a result of reading another post, which led to this link:

 

http://www.w3schools.com/php/php_ajax_database.asp

Archived

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

×
×
  • 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.