Forum Moderators: coopster
<html>
<body>
<?php
<form action = "phpForm3.php" value = "Submit" method = "POST">
<input type = "submit" value = "Go"/>
$result = mysql_query("SELECT * FROM Counties") or die(mysql_error());
if ($result)
{
print "<table width=200 border=1>\n";
print "<tr>\n";
print "<th> </th>\n";
print "<th> State </th>\n"; //2 fields in Counties table, State and County
print "<th> County </th>\n";
print "</tr>\n";
//create table
while ( $row = mysql_fetch_array($result) )
{
print "<tr>\n";
print "<td><input type=\"checkbox\" name=\"countyArray[]\" value=\"$row[CountyName]\"></td>\n";
echo "<td>{$row['State']}</td>\n";
echo "<td>{$row['CountyName']}</td>\n";
echo "</tr>\n";
}//end while
print "</table>\n";
}//end if
else
{
echo("<P>Error performing query: " .
mysql_error() . "</P>");
}
?>
</form>
</body>
</html>
Now this will create a nice looking table with checkboxes in the far left column. One problem, I cannot seem to associate the data (county, state) with the box that the user checked.
So, if they select the checkbox next to "CA Alemeda", then on the next page I want to display:
"You have selected: Alemeda, CA"
Any suggestions on how to do this?
<html>
<body>
<?php
if ( isset($_POST['submit']) ) { // if form is submitted, process it
for($i=1; $i<=$_POST['counties']; $i++) {
if ( isset($_POST["county$i"] ) ) {
print $_POST["county$i"]." is checked.<br/>";
}
}
} else { // if form isn't submitted, output the form
print "<form action=\"phpForm3.php\" method=\"POST\">\n";
$link = mysql_connect("", "", "");
mysql_select_db("");
$result = mysql_query("SELECT * FROM Counties") or die(mysql_error());
if ($result) {
print "<table width=200 border=1>\n";
print "<tr>\n";
print "<th> </th>\n";
print "<th> State </th>\n"; //2 fields in Counties table, State and County
print "<th> County </th>\n";
print "</tr>\n";
//create table
$i = 0;
while ( $row = mysql_fetch_array($result) ) {
$i++;
print "<tr>\n";
print "<td><input type=\"checkbox\" name=\"county$i\" value=\"$row[CountyName]\"></td>\n";
echo "<td>{$row['State']}</td>\n";
echo "<td>{$row['CountyName']}</td>\n";
echo "</tr>\n";
}//end while
print "</table>\n";
} else {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
}
print "<input type=\"hidden\" name=\"counties\" value=\"$i\"/>\n";
print "<input type=\"submit\" name=\"submit\" value=\"Go\"/>\n";
}
?>
</form>
</body>
</html>
Its going to take some time to get used to this
(conditional) {
statements...
}//end conditional
else {
statements...
}
Thanks again, I'll just comment it "code which associates checkboxes to values courtesy of Iceman@webmasterworld.com" or something to that effect (or is it affect?)
--Nick