The code below draws information from an sql table. It's very simple. A main table is generated at the bottom of the page, that includes all of the information from the sql table. Above the main table is a set of dropdown lists that draw information from individual columns in the same sql table.
There are two things that I would like to have happen, but don't know how to modify the code below to make them happen.
1) Set the dropdown lists so that they don't repeat same information... like days of the week for instance.
2) Set the dropdown lists so that when information is selected from them the main table at the bottom is narrowed down. Basically, rows that do not correspond with the selected information are not shown.
I've been sitting trying to wrap my head around this for a couple of hours now. Nothing. Any help would greatly be appreciated. Thanks
Code:
<form action="">
Where would you like to take the class?<br>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("username_redcross", $con);
$query="SELECT location FROM take_a_class";
$result = mysql_query($query);
echo "<select name=location value=''>Select Location</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[location]>$nt[location]</option>";
}
echo "</select>";
?>
<br><br>
On which date would you like to take the class?<br>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("username_redcross", $con);
$query="SELECT date FROM take_a_class";
$result = mysql_query($query);
echo "<select name=date value=''>Select Date</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[date]>$nt[date]</option>";
}
echo "</select>";
?>
<br><br>
Which day of the week is best for you?<br>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("username_redcross", $con);
$query="SELECT day FROM take_a_class";
$result = mysql_query($query);
echo "<select name=day value=''>Select Day</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[day]>$nt[day]</option>";
}
echo "</select>";
?>
</select>
<br><br>
Which time of day is best for you?<br>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("username_redcross", $con);
$query="SELECT time FROM take_a_class";
$result = mysql_query($query);
echo "<select name=time value=''>Select Time</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[time]>$nt[time]</option>";
}
echo "</select>";
?>
<br><br>
</form>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("username_redcross", $con);
$result = mysql_query("SELECT * FROM take_a_class");
echo "<table border='1'>
<tr>
<th>Class Type</th>
<th>Location</th>
<th>Date</th>
<th>Day</th>
<th>Time</th>
<th>Phone</th>
</tr>";while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['class_type'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['day'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "</tr>";
}
echo "</table>";mysql_close($con);
?>
Check out the site to see the output:
http://wildlamb.com/red-cross/index2.php?page=tac