So i have queried three columns from my sql table in PHP, and am displaying it.
while($row = sqlsrv_fetch_array($query))
{
$NAME[] = "$row[NAME]";
$CONTENT[] = "$row[CONTENT]";
$SPECIFIC[] = "$row[SPECIFIC]";
}
With this i have created three dropdown, all these arrays have same length.
$NAME_unique=array_unique($NAME);
$CONTENT_unique=array_unique($CONTENT);
$SPECIFIC_unique=array_unique($SPECIFIC);
echo "<div><table class='SearchBox'>";
echo "<thead></thead>";
echo "<tbody>";
echo "<tr>";
echo "<td>Name</td>";
echo "<td><select>"
echo "<option selected='selected' value='%'>Select</option>";
foreach($NAME_unique as $key => $value):
echo '<option value="'.$value.'">'.$value.'</option>';
endforeach;
echo "</select></td>";
echo "<td>Content</td>";
echo "<td><select>"
echo "<option selected='selected' value='%'>Select</option>";
foreach($CONTENT_unique as $key => $value):
echo '<option value="'.$value.'">'.$value.'</option>';
endforeach;
echo "</select></td>";
echo "<td>Specific</td>";
echo "<td><select>"
echo "<option selected='selected' value='%'>Select</option>";
foreach($SPECIFIC_unique as $key => $value):
echo '<option value="'.$value.'">'.$value.'</option>';
endforeach;
echo "</select></td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
Now what i want to do is create a filter that if i select a certain name: content and specifc are displayed accordingly. If i select content the specific is diplayed according. Three column look like this:
So my tables look like this:
NAME CONTENT SPECIFC
Gary Rivers Mississippi
Peter Florida Miami
Peter Texas Austin
Gary Rivers Hudson
Gary Lakes Michigan
Sarah Africa Zimbabwe
Peter Texas Houston
Sarah Asia China
Sarah Asia Japan
What i want is by default all these should be populated, what i currently have. But now if for NAME: Sarah is selected; it automatically changes the CONTENT to Asia, Africa and SPECIFC becomes Japan, China, Zimbabwe. Same way if Peter selected; CONTENT is Texas, Florida and SPECIFIC becomes Houston, Austin, Miami. Or if in default i select CONTENT to be Rivers; SPECIFC needs to be Mississipi, Hudson.
Now i have experience doing 1 drop down other using Javascript, HTML; but never 2 dropdwon on 1. Can this be done in PHP. I have read online about using ajax but i have no experience with it and could not find a good example. How to do it just using PHP/Javascript/jquery?