misteraven
08-07-2002, 11:23 AM
I'm still kind of new to PHP and have been stuck on a particular issue. I'm trying to develope a store locator that's basically a MySQL database of addresses that'll allow a person to search for a store address by either city, state or country. I've got most of it worked out, but was trying to figure out how I can limit the results shown to a certain number that would be predefined in variable. Further, if the results exceeded another number (also predefined ina variable), it would produce an error page where I could put in a message to narrow the search parameters. Any help or a link that might get me there would be very greatly appreciated. Here's the Search/Results Page so far...
<?php
include ("include/header.inc.php");
include ("include/dbconnect.php");
if ($searchstring)
{
$sql="SELECT * FROM $table WHERE $searchtype LIKE '%$searchstring%' ORDER BY storename ASC";
$result = mysql_query($sql);
$resultsnumber = mysql_numrows($result);
echo "<table>";
echo "<tr><td>$resultsnumber results found<br><br></td></tr>";
$alternate = "2";
while ($myrow = mysql_fetch_array($result))
{
$storename = $myrow["storename"];
$id = $myrow["id"];
if ($alternate == "1") {
$color = "#ffffff";
$alternate = "2";
}
else {
$color = "#efefef";
$alternate = "1";
}
echo "<tr><td>$storename</td>";
echo "<td><a href='view.php?id=$id'>see details</a></td></tr>";
}
echo "<tr><td><br><br>Look <a href='az_index.php'>alphabetically</a> or <a href='$PHP_SELF'>search again</a></td></tr>";
echo "</table>";
}
else
{
?>
<form method="POST" action="<? $PHP_SELF ?>">
<table border="0" cellspacing="2" width="380">
<tr>
<td><b>Search</b></td>
<td><b>Variable</b></td>
</tr>
<tr>
<td valign="top">
<input type="text" name="searchstring" size="35">
</td>
<td>
<input type="radio" name="searchtype" value="storename">Storename<br>
<input type="radio" name="searchtype" value="city">City<br>
<input type="radio" name="searchtype" value="state" checked>State<br>
<input type="radio" name="searchtype" value="zip">Zip<br>
<input type="radio" name="searchtype" value="country">Country</td>
</tr>
<tr><td><input type="submit" value="Submit"></td>
<td>[nbsp]</td></tr>
</table>
</form>
<?
}
include ("include/footer.inc.php");
?>
<?php
include ("include/header.inc.php");
include ("include/dbconnect.php");
if ($searchstring)
{
$sql="SELECT * FROM $table WHERE $searchtype LIKE '%$searchstring%' ORDER BY storename ASC";
$result = mysql_query($sql);
$resultsnumber = mysql_numrows($result);
echo "<table>";
echo "<tr><td>$resultsnumber results found<br><br></td></tr>";
$alternate = "2";
while ($myrow = mysql_fetch_array($result))
{
$storename = $myrow["storename"];
$id = $myrow["id"];
if ($alternate == "1") {
$color = "#ffffff";
$alternate = "2";
}
else {
$color = "#efefef";
$alternate = "1";
}
echo "<tr><td>$storename</td>";
echo "<td><a href='view.php?id=$id'>see details</a></td></tr>";
}
echo "<tr><td><br><br>Look <a href='az_index.php'>alphabetically</a> or <a href='$PHP_SELF'>search again</a></td></tr>";
echo "</table>";
}
else
{
?>
<form method="POST" action="<? $PHP_SELF ?>">
<table border="0" cellspacing="2" width="380">
<tr>
<td><b>Search</b></td>
<td><b>Variable</b></td>
</tr>
<tr>
<td valign="top">
<input type="text" name="searchstring" size="35">
</td>
<td>
<input type="radio" name="searchtype" value="storename">Storename<br>
<input type="radio" name="searchtype" value="city">City<br>
<input type="radio" name="searchtype" value="state" checked>State<br>
<input type="radio" name="searchtype" value="zip">Zip<br>
<input type="radio" name="searchtype" value="country">Country</td>
</tr>
<tr><td><input type="submit" value="Submit"></td>
<td>[nbsp]</td></tr>
</table>
</form>
<?
}
include ("include/footer.inc.php");
?>