The code below works like a charm, but I have been having trouble getting each result row to alternate colors. For example I would like each odd numbered row to have a white BG color and each even result row a gray BG color.
I believe if memory serves that the spot that mentions gray & white are part of my attempt at accomplishing this, but it is not working.... something is wrong.
If someone could show me the coding for this and tell me where to place it in the current code, it would be greatly appreciated.
Thanks - vellum
code starts here:
<!-- php starts here -->
<?php
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "<p align=center><b>You have not entered search details. Please go back and try again.</b></p>";
exit;
}
/* Connecting, selecting database */
@ $db = mysql_connect("hostsite", "user", "password"
or die("Could not connect"
mysql_select_db("churches" or die("Could not select database"
/* Performing SQL query */
$query = "SELECT * FROM church WHERE ".$searchtype." LIKE '%".$searchterm."%' order by 'name' asc";
$result = mysql_query($query) or die("Query failed"
$num_results = mysql_num_rows($result);
$counter = 0;
print "<p><b>Your search produced ".$num_results." matches.</b></p>";
/* Printing results in HTML */
print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"500\" align=\"center\">\n";
print "<tr>\n";
print "<td bgcolor=#0099FF colspan=\"3\" width=\"50%\" align=\"center\"><p><b>Organization</b></p></td>\n";
print "<td bgcolor=#0099FF colspan=\"5\" align=\"center\"><p><b>Information</b></p></td>\n";
print "</tr>\n";
while ($row = mysql_fetch_assoc($result)) {
print "<tr>\n";
//print ($counter % 2 == 0)? "gray" : "white";
printf("<td colspan=\"3\"><p><b>%s</b><br> %s<br> %s</td><td align=\"right\" colspan=\"5\"><p>%s<br> %s, %s. %s<br> %s</td>\n", $row['Name'], $row['Pastor'], $row['Denomination'], $row['Address'], $row['City'], $row['State'], $row['Zip'], $row['Phone']);
print "\t</tr>\n";
$counter++;
}
print "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($db);
?>
<!-- php ends here -->
I believe if memory serves that the spot that mentions gray & white are part of my attempt at accomplishing this, but it is not working.... something is wrong.
If someone could show me the coding for this and tell me where to place it in the current code, it would be greatly appreciated.
Thanks - vellum
code starts here:
<!-- php starts here -->
<?php
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "<p align=center><b>You have not entered search details. Please go back and try again.</b></p>";
exit;
}
/* Connecting, selecting database */
@ $db = mysql_connect("hostsite", "user", "password"
or die("Could not connect"
mysql_select_db("churches" or die("Could not select database"
/* Performing SQL query */
$query = "SELECT * FROM church WHERE ".$searchtype." LIKE '%".$searchterm."%' order by 'name' asc";
$result = mysql_query($query) or die("Query failed"
$num_results = mysql_num_rows($result);
$counter = 0;
print "<p><b>Your search produced ".$num_results." matches.</b></p>";
/* Printing results in HTML */
print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"500\" align=\"center\">\n";
print "<tr>\n";
print "<td bgcolor=#0099FF colspan=\"3\" width=\"50%\" align=\"center\"><p><b>Organization</b></p></td>\n";
print "<td bgcolor=#0099FF colspan=\"5\" align=\"center\"><p><b>Information</b></p></td>\n";
print "</tr>\n";
while ($row = mysql_fetch_assoc($result)) {
print "<tr>\n";
//print ($counter % 2 == 0)? "gray" : "white";
printf("<td colspan=\"3\"><p><b>%s</b><br> %s<br> %s</td><td align=\"right\" colspan=\"5\"><p>%s<br> %s, %s. %s<br> %s</td>\n", $row['Name'], $row['Pastor'], $row['Denomination'], $row['Address'], $row['City'], $row['State'], $row['Zip'], $row['Phone']);
print "\t</tr>\n";
$counter++;
}
print "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($db);
?>
<!-- php ends here -->