58 users online (1 members and 57 guests)  


  Results 1 to 1 of 1

Related

  1. Need Help : mysql advanced SELECT issue    Forum: Databases
    Replies: 6
  2. Replies: 4
  3. MySQL Select statement    Forum: Databases
    Replies: 1
  4. Query REturns Empty    Forum: PHP Forum
    Replies: 1
  5. dat to mysql import - or redirect authorization    Forum: Website Scripts Forum
    Replies: 5
  1. #1
    galiant's Avatar
    New User

    Status
    Offline
    Join Date
    Dec 2010
    Posts
    1

    if mysql select returns no results redirect

    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:
    HTML Code:
    <?php
    mysql_connect ("localhost", "login","removed")  or die (mysql_error());  
    mysql_select_db ("peterson_zipcode"); 
    $term = $_POST['term'];  
    $sql = mysql_query("select * from reps_zip where zip like '%$term%'");  
    if ($row = mysql_fetch_array($sql)){   
    	echo '<img src="'.$row['picture'].'" width=274>'; 
    	echo '<br/>'.$row['name'];  
    	echo '<br/> <a href="'.$row['page'].'">Contact Info</a>'; 
    	echo '<br/><br/>';  
    }  else {
        // the query executed, check if there are any rows in the result set
        if(mysql_num_rows($row) > 0){	echo '<br/>TEST<br/>';  
            // code to execute when there are any row(s) in the result set
        } 
    }  
    
    ?>
    Last edited by HTML; 12-15-2010 at 10:12 PM. Reason: subscribe