Jump to content

Archived

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

leon

dynamic drop down lists help

Recommended Posts

Hello,
I am working on dynamic drop-down lists, but I have some questions,Here is the code:

[code]
<?php
include ('./db/sql.php');

if(isset($_GET['parent_id'])){
$parent=$_GET['parent_id'];

$query="SELECT alt_name, image_thumb FROM products
            WHERE parent_id='$parent'";

$sql=$query;

$result=mysql_query($sql);
$row=mysql_num_rows($result);
$data=mysql_fetch_assoc($result);
if(!$row){
echo "no results found." .mysql_error();
}
}
?>
........some html codes


//form
<td height="5"><form name="order" method="post" target="" action="">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <th width="15" height="10" scope="row"></th>
              <td width="116" class="baslik">Select Category</td>
              <td width="144"><label>
                <select name="navigation" size="1" id="navigation" onChange="go()">
                  <option value="http://localhost/order.php" >select a category</option>
                  <option value="http://localhost/order.php?parent_id=1" <? if($parent==1){ ?> selected="selected" <? }?> >Travertine</option>
                  <option>Marble</option>
                  <option>Limestone</option>
                  <option>Slate</option>
                  <option>Mosaics</option>
                  <option>Borders</option>
                  <option>Bathware</option>
                </select>
              </label></td>
              <td width="294" height="10"></td>
            </tr>
            <tr>
              <th height="10" scope="row"></th>
              <td class="baslik"></td>
              <td></td>
              <td height="10"></td>
            </tr>
            <tr>
              <th height="10" scope="row"></th>
              <td class="baslik">Product Name</td>
              <td><label>
              <select name="select2">
                <option>select a product</option>
<?php
    if(isset($parent)){ do{?>
                <option> <?php echo "{$data['alt_name']}";}
while($data=mysql_fetch_assoc($result)); }?></option>
              </select>
              </label></td>
              <td height="10"></td>
            </tr>
            <tr>
              <th height="10" scope="row"></th>
              <td class="baslik"></td>
              <td></td>
              <td height="10"></td>
            </tr>
            <tr>
              <th height="10" scope="row"></th>
              <td class="baslik">Size: (mm) </td>
              <td><label>
                <select name="select3" size="1">
                  <option>select size</option>
                </select>
              </label></td>
              <td width="294" height="10"></td>
            </tr>
            <tr>
              <th height="10" scope="row"></th>
              <td class="baslik"></td>
              <td></td>
              <td height="10"></td>
            </tr>
           
            <tr>
              <th height="10" scope="row"></th>
              <td class="baslik">How many sqm/ item? </td>
              <td><label>
                <input name="textfield" type="text" size="15">
              </label></td>
              <td height="10"></td>
            </tr>
           
            <tr>
              <th height="10" scope="row"></th>
              <td class="baslik"></td>
              <td></td>
              <td height="10"></td>
            </tr>
           
            <tr>
              <th height="10" scope="row"></th>
              <td class="mycss"></td>
              <td></td>
              <td width="294" height="10"></td>
            </tr>
            <tr>
              <th height="10" scope="row"></th>
              <td class="mycss"></td>
              <td><div align="center"></div></td>
              <td width="294" height="10"></td>
            </tr>
          </table>
        </form></td>
[/code]
What I am trying to do is, when user selects a product category,(travertine in this code), it retrieves all the product names under that category from the databse (the page is reloaded, I do not wanna use javascript apart from onChange(go)).

And then the problem comes, when the user selects a product, I wanna retrieve related info for that product, size, price maybe image. I cannot modify the code because it is a loop as the following.
[code]
<select name="select2">
                <option>select a product</option>
<?php
    if(isset($parent)){ do{?>
                <option> <?php echo "{$data['alt_name']}";}
while($data=mysql_fetch_assoc($result)); }?></option>
              </select>
[/code]
How can I overcome this problem?
Thanks in advance....

Share this post


Link to post
Share on other sites
[code]

//////////start///////////

<select name="what_ever">

<?php
//datbase connection

// $query select statement

$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){
?>

<option value="<?php echo $record['what_ever_you_want']; ?>">
<?php echo $record['what_ever_you_want']; ?></option>

<?}?>

</select>
/////end///////
[/code]

Share this post


Link to post
Share on other sites
Thanks for your help, but I am afraid that will not solve my problem. My dropdown list will have three steps.
Firstly to select a product category:
[code]
<select name="navigation" size="1" id="navigation" onChange="go()">
                  <option value="http://localhost/order.php" >select a category</option>
                  <option value="http://localhost/order.php?parent_id=1" <? if($parent==1){ ?> selected="selected" <? }?> >Travertine</option>
                  <option>Marble</option>
                  <option>Limestone</option>
                  <option>Slate</option>
                  <option>Mosaics</option>
                  <option>Borders</option>
                  <option>Bathware</option>
                </select>
[/code]

and then depending on the selection, the page reloads itself, the names of the products are pulled down from the database:
[code]
<select name="product_names">
                <option>select a product</option>
<?php
    if(isset($parent)){ do{?>
                <option> <?php echo "{$data['alt_name']}";}
while($data=mysql_fetch_assoc($result)); }?></option>
              </select>
[/code]

And the last step is again depends on the selection of a product name. When a particular product is selected, it is again reloaded ( or should be, I do not know how to do it yet) and with the proper mysql query, its size or images are retrieved.
[code]
<select name="select3" size="1">
                  <option>select size</option>
                </select>
[/code]
So how can I modify this last step to achieve what I am trying to do?
Thanks again...

Share this post


Link to post
Share on other sites
sorry but this idear of yours is i think javascript and alax

useally the user use a select box to search or input data and so on in php

so i dont relly understand what the objective is sorry.

Share this post


Link to post
Share on other sites

×

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.