PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
First time using a DB(MYSQL) and php to produce a little search.
I have a list of zip codes for sales reps. The intial search worked great, but I want to have an if/else so if someone enters a zip code that is not in my database they are taken to a different page or recieve a message.
Not haveing much luck.
Here is the code I have and need the code help for if the zip is not in the database... beable to post text or link to a page:
<?php
// in this example, id is the PK
$count_query = mysql_query("SELECT COUNT(id) FROM reps_zip
WHERE zip like '%$term%' ");
//
$array = mysql_fetch_array($count_query);
// the result of the above is in the first value of
// the array
$rows = $array[0];
if ($rows == 0) {
// here you will probably use a function because
// you might get a 'headers already sent error
// message
header('redirect: otherpage.php');
}
else {
// here the value is indeed in your table so continue
// as normal
$sql = mysql_query("select * from reps_zip where zip like '%$term%'");
}
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering