[nycphp-talk] Help with error statement
Paul
paul at gubavision.com
Thu Nov 16 12:19:19 EST 2006
If I do as I think you suggested here:
On Nov 16, 2006, at 11:35 AM, Rob Marscher wrote:
> You want to use mysql_num_rows -
> http://us3.php.net/manual/en/function.mysql-num-rows.php - after your
> query. You can then do an if statement to check if mysql_num_rows !
> = 0
> before doing the while loop:
>
> $sql_events = mysql_query("SELECT * FROM area36 WHERE zipcode
> ='$key'") or die (mysql_error());
> if (mysql_num_rows() !== 0)
> {
> while ($row = mysql_fetch_array($sql_events)) {
> // stuff in here
> }
> }
> else
> {
> // error - no records found
> }
My correction snippet based on that here:
{
$sql_events = mysql_query("SELECT * FROM area36 WHERE zipcode
='$key'") or die (mysql_error());
if (mysql_num_rows($sql_events) !== 0)
{
while ($row = mysql_fetch_array($sql_events)) {
$dist = $row['dist'];
$day = $row['day'];
$town = $row['town'];
$time = $row['time'];
$place = $row['place'];
$street = $row['street'];
$type = $row['type'];
$Special = $row['Special'];
$hca = $row['hca'];
$ns = $row['ns'];
//row count for alternating colors
$row_color = ($row_count % 2) ? $color1 : $color2;
//create tables for data row loop
echo "<tr>
<td class='$row_color'>$dist</td>
<td class='$row_color'>$day</td>
<td class='$row_color'>$town</a></td>
<td class='$row_color'>$time</a></td>
<td class='$row_color'>$place</a></td>
<td class='$row_color'>$street</a></td>
<td class='$row_color'>$type</a></td>
<td class='$row_color'>$Special</a></td>
<td class='$row_color'>$hca</a></td>
<td class='$row_color'>$ns</a></td>
</tr>";
// Add 1 to the row count
$row_count++;
}
}
// error statement if no locations are found within search radius
else {
echo 'Sorry, your search returned no locations. Try using a larger
radius to search.';
}
Returns the error statement each time there is an x amount positive
result. This was the exact problem I was having. So what I get is
the error repeated x amount of times than my table is built with the
actual results. What am I missing?
Paul Guba
More information about the talk
mailing list