jjmusicpro Posted July 12, 2007 Share Posted July 12, 2007 Ok i am sure someone can figure this out, I've been banging my head trying to figure it out. The user will come to the index page, and type in a zip code. from there it will post to itself, and do either of 3 things. If no results are found display "No results found" If 1 result is found, i wanted it to redirect to that url, i cant seem to get that javascript to work. and if 2 or more results are found, then loop through like i was doing, and give me the results. I cant seem to get this right...it wont redirect when there is 1 result. <?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 "Nothing Found!"; }else if($count=="1"){ echo "<script type='text/javascript'> window.location = 'http://www.google.com/' </script>"; }else{ echo "Located $count result(s)<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 } ?> Quote Link to comment Share on other sites More sharing options...
cmgmyr Posted July 12, 2007 Share Posted July 12, 2007 when you are using numbers you should usually do this: if($x == 0)... for the redirect use: header() or a meta refresh. Those might work a little better. Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted July 12, 2007 Author Share Posted July 12, 2007 when you are using numbers you should usually do this: if($x == 0)... for the redirect use: header() or a meta refresh. Those might work a little better. i cant use header() because this php is in the middel of my code. How do i do a meta refresh? Quote Link to comment Share on other sites More sharing options...
cmgmyr Posted July 12, 2007 Share Posted July 12, 2007 echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=page.php\">"; This will go to page.php after 2 seconds. Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted July 12, 2007 Author Share Posted July 12, 2007 echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=page.php\">"; This will go to page.php after 2 seconds. how would i put the value of url_redirect that is pulled fromt he DB in the in that? Quote Link to comment Share on other sites More sharing options...
cmgmyr Posted July 12, 2007 Share Posted July 12, 2007 }elseif($count == 1){ echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=http://google.com\">"; } you wouldn't want to put that in the else Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted July 12, 2007 Author Share Posted July 12, 2007 }elseif($count == 1){ echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=http://google.com\">"; } you wouldn't want to put that in the else thats where i need it to go becuase if it matches the zip code, and only brings back 1 result, i need it to redirct to the redirct_url thats in the database with that zip. Quote Link to comment Share on other sites More sharing options...
cmgmyr Posted July 12, 2007 Share Posted July 12, 2007 Then wouldn't you want this: }elseif($count == 1){ while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $site = $row['redirect_url'] ; echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=$site\">"; } } because if you have more then 1 row returned you want a link, not a refresh. Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted July 12, 2007 Author Share Posted July 12, 2007 Then wouldn't you want this: }elseif($count == 1){ while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $site = $row['redirect_url'] ; echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=$site\">"; } } because if you have more then 1 row returned you want a link, not a refresh. This is what i have now, and i cant seem to get it to go tot he new site. the page flashes, but it wont go anywhere.. <?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 '<b>No locations found for your zip.</b><br>Please fill out the form below so we can help your further.<p>'; }else if($count=="1"){ $site = $row['redirect_url'] ; echo "<META HTTP-EQUIV=Refresh CONTENT=\"4; URL=$site\">"; }else{ echo "Located $count result(s)<br /><br><table width=\"300\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">"; while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo '<tr><td><img src=mm_smaller.gif></td><td><b>'.$row['company_name'] . '</b>'. '<br>' .'<a href="'. $row['redirect_url'] . '"> Visit Website </a>'. ' ' .'<br>' . $row['notes_1'] . '</td><p></tr><p><p>'; }echo '</tr></table>'; } }else{ // nothing } ?> Quote Link to comment Share on other sites More sharing options...
cmgmyr Posted July 12, 2007 Share Posted July 12, 2007 did you try to echo $site and see if it came up with anything? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.