Jump to content


Photo

dynamic drop down lists help


  • Please log in to reply
3 replies to this topic

#1 leon

leon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 28 July 2006 - 06:26 AM

Hello,
I am working on dynamic drop-down lists, but I have some questions,Here is the 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>
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.
<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>
How can I overcome this problem?
Thanks in advance....

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 06:36 AM


//////////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///////

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 leon

leon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 28 July 2006 - 07:42 AM

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:
<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>

and then depending on the selection, the page reloads itself, the names of the products are pulled down from the database:
<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>

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.
<select name="select3" size="1">
                  <option>select size</option>
                </select>
So how can I modify this last step to achieve what I am trying to do?
Thanks again...

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 08:01 AM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users