gubaguba
11-14-2006, 02:03 PM
I have the beginings of a zipcode dealer locator. Currently it has actual zip and milage numbers but I will replace these with variables latter. What I would like for it to do is to return an error message if no meetings are found. Originally I thought to use zip count as shown but realised a value of one is always returned for the zip entered. There could actually be a one location associated with that zip as well. So I am open to suggestions. Here is what I have so far.
<?php
require_once('zipcode.class.php');
mysql_connect("localhost", "something", "something") or die(mysql_error());
mysql_select_db("ziplocator") or die(mysql_error());
$z = new zipcode_class;
echo "<table>";
echo "<center><tr> <th>Dist</th><th>Day</th> <th>Town</th><th>Time</th><th>Place</th><th>Street</th><th>Type</th><th>Format</th><th>HCA</th><th>NS</th> </tr>";
// Define your colors for the alternating rows
$color1 = "meet";
$color2 = "altmeet";
$row_count = 0;
$zips = $z->get_zips_in_range('07732', '10', _ZIPS_SORT_BY_DISTANCE_ASC, true);
foreach ($zips as $key => $value){
if(isset($key) && count($key) > 0) {
$sql_events = mysql_query("SELECT * FROM area36 WHERE zipcode ='$key'") or die (mysql_error());
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'];
/* Now we do this small line which is basically going to tell
PHP to alternate the colors between the two colors we defined above. */
$row_color = ($row_count % 2) ? $color1 : $color2;
// Echo your table row and table data that you want to be looped over and over here.
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++;
}
}
else {
echo 'Sorry, your search returned no results for dealers in your location';
}
}
// Close out your table.
echo "</table>";
?>
Thanks
Paul Guba
<?php
require_once('zipcode.class.php');
mysql_connect("localhost", "something", "something") or die(mysql_error());
mysql_select_db("ziplocator") or die(mysql_error());
$z = new zipcode_class;
echo "<table>";
echo "<center><tr> <th>Dist</th><th>Day</th> <th>Town</th><th>Time</th><th>Place</th><th>Street</th><th>Type</th><th>Format</th><th>HCA</th><th>NS</th> </tr>";
// Define your colors for the alternating rows
$color1 = "meet";
$color2 = "altmeet";
$row_count = 0;
$zips = $z->get_zips_in_range('07732', '10', _ZIPS_SORT_BY_DISTANCE_ASC, true);
foreach ($zips as $key => $value){
if(isset($key) && count($key) > 0) {
$sql_events = mysql_query("SELECT * FROM area36 WHERE zipcode ='$key'") or die (mysql_error());
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'];
/* Now we do this small line which is basically going to tell
PHP to alternate the colors between the two colors we defined above. */
$row_color = ($row_count % 2) ? $color1 : $color2;
// Echo your table row and table data that you want to be looped over and over here.
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++;
}
}
else {
echo 'Sorry, your search returned no results for dealers in your location';
}
}
// Close out your table.
echo "</table>";
?>
Thanks
Paul Guba