|
-
Jul 12th, 2007, 12:29 PM
#1
Thread Starter
Frenzied Member
Can get record to display correct
I still cant seem to get this to work right.
If there is only 1 result, i wanted it to redirect to the redirecturl, in my datbase, if there are no reults, then diplay "NO RESULTS"
and if there are more then 1 result, loop through and display them out.
PHP Code:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
require_once ('connect.php');
require_once ('opendb.php');
$zipcode = $_POST['zipcode_entered_search'];
$query = "SELECT * FROM zipcodes WHERE zipcode='$zipcode'";
$result = @mysql_query ($query);
$count = mysql_num_rows($result); //number of results
if ($count == 0){
echo "No localtions are found";
}else if($count == 1){
//redirect
}else if($count > 1){
echo "<b>Located $count result(s)</b><br />";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo $row['company_name'] . '<br>' .'<a href="'. $row['redirect_url'] . '"> Visit Website </a>'. ' ' .'<br>' . $row['notes_1'] . '<p>';
}
}
}
}else{
// nothing
}
?>
-
Jul 12th, 2007, 12:50 PM
#2
Addicted Member
Re: Can get record to display correct
try removing the @ from mysql_query.
edit:
also, is zipcode stored in your database as a varchar or an integer? If it's stored as an integer you should remove the single quotes around $zipcode in your query.
Last edited by asterix299; Jul 12th, 2007 at 12:53 PM.
-
Jul 12th, 2007, 12:57 PM
#3
Thread Starter
Frenzied Member
Re: Can get record to display correct
its stored as a varchar.
I tried to remove the @ in front, and it always displays "no records found"
-
Jul 12th, 2007, 01:04 PM
#4
Addicted Member
Re: Can get record to display correct
well my only other idea is that there's something wrong with the table in the dbase... try deleting it and remaking it.
-
Jul 12th, 2007, 01:14 PM
#5
Thread Starter
Frenzied Member
Re: Can get record to display correct
Its something with my if/else's
It works fine before i add another else if
-
Jul 12th, 2007, 01:23 PM
#6
Addicted Member
Re: Can get record to display correct
I'm pretty sure this doesn't matter but I've never made my else if's two words. I'm not sure if php differentiates between the two but try making it elseif rather than else if.
-
Jul 12th, 2007, 01:30 PM
#7
Thread Starter
Frenzied Member
Re: Can get record to display correct
the if elses were working right, its just when i added another if else to the mix.
-
Jul 12th, 2007, 01:32 PM
#8
Thread Starter
Frenzied Member
Re: Can get record to display correct
also, the part where if it finds 1 result, its not redirecting to the URL
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|