vinus patel
vinus patel

Reputation: 79

populate 2nd dropdown by select first dropdown value in php

I am declared two select. once i select value in first select then i will fetch value in second select.

<?php
$result1 = mysql_query("SELECT row1 FROM information");?>
<select id='select1'>
<?php
while($row=mysql_fetch_array($result1))
{
if($row['row1']!=NULL)
{
echo "<option value='$row[row1]'>$row[row1]</option>";
}
}?>
</select><br/><br/>
<?php
//*******************************************  
$result1 = mysql_query("SELECT column1 FROM information");
echo "<select id='select2'>";
while($row=mysql_fetch_array($result1))
{
if($row['column1']!=NULL)
{
echo "<option value='$row[column1]'>$row[column1]</option>";
}
}?>
</select>

Upvotes: 0

Views: 354

Answers (1)

Alvar FinSoft Soome
Alvar FinSoft Soome

Reputation: 740

You have two possibilities:

  1. Use jQuery + ajax to build dynamically second select after first (onselect event)
  2. Submit form or redirect user to same page with selected value from first select and if it is given (check in PHP from $_GET or $_POST) and if it is - generate second select with this info

Upvotes: 1

Related Questions