Jump to content

Using drop down boxes connected to oracle


Recommended Posts

Hi,

 

Im looking at using two drop down boxes one which will hold a selection of values and then depending on those values i want the second drop down box to be filled by a query from the database for example.

 

In the first drop down box i select search by type and then in the second I want all the types from the product type table to be listed! The user will then select the type they want to search for and a query is run and the results returned for every record that the specified type is used.

 

Any suggestions: Im new to oracle and php so go easy on me! Thanks

Link to comment
Share on other sites

  • 3 months later...

You could use AJAX to populate the second dropdown box dynamically, but I don't think you're looking for a solution that sophisticated.

 

Instead, try this: Make a form that submits to itself, and make the PHP script that creates the form check to see if the variable from the first dropdown box was submitted with the request.

 

<form name='theform'>
<select name='type' onChange='document.theform.submit()'>
<?
$DB = oci_connect("user", "pswd", "db");
$get_types = OCIParse($DB, "select distinct type from product");
OCIExecute($get_types);
while($type = oci_fetch_array($get_types))
   echo "<option value='{$type['TYPE']}' " . ((isset($_GET['type']) && $_GET['type'] == $type['TYPE']) ? "selected" : "") . ">{$type['TYPE']}</option>\n";
OCIFreeStatement($get_types);
?>
</select>
<p>
<?
if(isset($_GET['type'])){
   echo "<select name='product'>\n";
   $get_products = OCIParse($DB, "select product from product where type = :type");
   ocibindbynname($get_products, ":type", $_GET['type']);
   OCIExecute($get_products);
   while($product = oci_fetch_array($get_products))
      echo "<option value='{$product['PRODUCT']}'>{$product['PRODUCT']}</option>\n":
   OCIFreeStatement($get_products);
   echo "</select>";
}
?>
<input type=submit>
</form>

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.