Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Multiple dependent dropdoun from mysql db.

Codes here !

Moderators: macek, egami, gesf

Multiple dependent dropdoun from mysql db.

Postby sachinkr » Sun Sep 09, 2012 9:38 pm

Hi ,
I am Sachin. I am new to php/MySQL.Please some one can help me i am having problem in this type of programmer.Here is a example.It will help me in my work.
The table has predefined data .Using PHP i want to create 3 dynamic

drop downs for "new" table having 8 columns and 5 rows.1st drop down for "A" in the table.

It will retrieve the distinct values.after selecting the 1st drop down the 2nd drop down "B" retrieve

the related values of 1st selection.After selecting 2nd drop down the 3rd drop down for "C" retrieves

the related values from 2nd selection. After selecting 3rd drop down it will fetch the the total row and display

in the UI.

A B C D E F G H
1000 100 10 1 5 6 8 9
1000 200 20 2 6 7 9 8
2000 100 20 3 7 8 7 7
2000 100 10 4 8 9 6 6
2000 200 20 5 7 8 8 8

A B C after selecting in c it will look like this :- A B C D E F G H

[2000] [100] [20] 2000 100 20 3 6 7 8 9




please some one help me the code.

Regards Sachin. :help: :oops:
sachinkr
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Sep 08, 2012 8:54 pm

Re: Multiple dependent dropdoun from mysql db.

Postby NigelRen » Tue Sep 11, 2012 11:54 pm

Can you post the code you have so far, people will be more willing to help if they see you've made a start.
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: Multiple dependent dropdoun from mysql db.

Postby sachinkr » Thu Sep 13, 2012 11:08 pm

Thanks for responding NigelRen.


Here is the code.
Code: Select all
<html>
<body>
<form name="form1" method="post" action="">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("store", $con);
$wd=mysql_query("select distinct A from X");
echo "<select name= \"select\">";
while($row = mysql_fetch_array($wd))
{
       echo "<option value='".$row['A']."'>".$row['A']."</option>";
}
      echo "</select>";

      $fd=mysql_query("select distinct B from  X where A=$wd");
      echo "<select name= \"select\">";
      while($row = mysql_fetch_array($fd));
{
       echo "<option value='".$row['B']."'>".$row['B']."</option>";
}
      echo "</select>";
      $query="select  distinct C from X where ";
      $result=mysql_query($query);
      echo"<select name='select'  onChange='form1.submit()'>";
      while($row=mysql_fetch_array($result))
{
   $strselect='';
   if($_POST[select]==$row['c']) $strselect="selected='selected'";
echo"<option value='".$row['c']."' $strselect>".$row['c']."</option>";
}
echo "</select>";
//mysql_close($con);
?>
<?php
if($_POST['select'])
{
$sql = "select * from vibrating_feeder_details where thickness=$_POST[select]";
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
?>
mysql_close($con);
<table width="90%" border="5">
  <tr>
    <td>A</td>
    <td>B</td>
    <td>C</td>
    <td>D</td>
    <td>E</td>
    <td>F</td>
    <td>G</td>
    <td>H</td>
    </tr>
   <tr>
    <td><?php echo $row['A'];?></td>
   <td><?php echo $row['B'];?></td>
   <td><?php echo $row['C'];?></td>
   <td><?php echo $row['D'];?></td>
   <td><?php echo $row['E'];?></td>
   <td><?php echo $row['F'];?></td>
   <td><?php echo $row['G'];?></td>
   <td><?php echo $row['H'];?></td>
   </tr>
   </table>
<?php
}
?>
</body>
</html>



I want to make it dynamic depending upon the user selection.
Thanks
Regards Sachin.
sachinkr
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Sep 08, 2012 8:54 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron