Jump to content

dynamic drop down lists help


leon

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....
Link to comment
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]
Link to comment
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...
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.