Results 1 to 8 of 8

Thread: Can get record to display correct

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    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($resultMYSQL_ASSOC)){ 
           echo 
    $row['company_name'] . '<br>' .'<a href="'$row['redirect_url'] . '"> Visit Website </a>'' '  .'<br>' $row['notes_1'] . '<p>'
        } 
        } 
      }
      }else{ 
        
    // nothing
      

    ?>

  2. #2
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    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.

  3. #3

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    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"

  4. #4
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    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.

  5. #5

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Can get record to display correct

    Its something with my if/else's

    It works fine before i add another else if

  6. #6
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    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.

  7. #7

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Can get record to display correct

    the if elses were working right, its just when i added another if else to the mix.

  8. #8

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    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
  •  



Click Here to Expand Forum to Full Width