Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post

    problem with else statement

    i have this search engine and i want it to display the words "Search Returned No Results" if $row is empty..... but i did it and it posts "Search Returned No Results" even if it did return results.... i also tried else if and it didnt work
    -----------------
    PHP Code:
    <?php 
                      $q 
    $_GET['q'];
                      if(isset(
    $q)){
          
    $aa mysql_connect("localhost""root""");
          
    $db mysql_select_db("whmx_store",$aa);
          
    $sql_select "SELECT * FROM cds WHERE keywords LIKE '%$q%' ORDER BY artist ASC";
          
    $result mysql_query($sql_select) or die ("Queryproblem: " mysql_error());

          while (
    $row mysql_fetch_array($result)) {
                  print 
    "<table width='100%' border='0' cellspacing='0'>";
                  print 
    "<tr>";
                  print 
    "<td width='10%' rowspan='3'>&nbsp;<img src='$row[2]' width='44' height='44'>&nbsp;";
                  print 
    "<td width='80%' align='left'><font face='arial' size='2' color='navy'><b><a href='$row[4]'>$row[1] - <em>$row[0]</a></em></b></font>";
                  print 
    "<td width=10%' align='center'><a href='$row[3]'><img src='34y.gif' border='0'></a></td>";
                  print 
    "</tr>";
                  print 
    "<tr>";
                  print 
    "<td align='left'>";
                  
    printf ("%.145s...""<font face='arial' size='1' color='navy'>$row[6]</font>");
                  print 
    "</td>";
                  print 
    "</tr>";
                  print 
    "<tr>";
                  print 
    "<td align='left'>";
                  
    printf ("%.130s...""<font face='arial' color='blue' size='1'><a href='$row[4]'>[url]http://store.whmx.com/[/url]$row[4]</a></font>");
                  print 
    "</td>";
                  print 
    "</tr>";
                  print 
    "</table><hr color='orange' width='97%'>";
                  }
        
        }
                  if(empty(
    $row)){
            echo 
    "<font face='arial' size='3' color='navy'><center><b>No Results found for your search:</b> <em>$q</em></center></font>";
            }
                  
    ?>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Try this
    PHP Code:
    <?php 
    $q 
    $_GET['q'];
    if(isset(
    $q)){
        
    $aa mysql_connect("localhost""root""");
        
    $db mysql_select_db("whmx_store",$aa);
        
    $sql_select "SELECT * FROM cds WHERE keywords LIKE '%$q%' ORDER BY artist ASC";
        
    $result mysql_query($sql_select) or die ("Queryproblem: " mysql_error());

        
    $rowsfound mysql_num_rows($result);

        if(
    $rowsfound 0){
            while (
    $row mysql_fetch_array($result)) {
                  print 
    "<table width='100%' border='0' cellspacing='0'>";
                  print 
    "<tr>";
                  print 
    "<td width='10%' rowspan='3'>&nbsp;<img src='$row[2]' width='44' height='44'>&nbsp;";
                  print 
    "<td width='80%' align='left'><font face='arial' size='2' color='navy'><b><a href='$row[4]'>$row[1] - <em>$row[0]</a></em></b></font>";
                  print 
    "<td width=10%' align='center'><a href='$row[3]'><img src='34y.gif' border='0'></a></td>";
                  print 
    "</tr>";
                  print 
    "<tr>";
                  print 
    "<td align='left'>";
                  
    printf ("%.145s...""<font face='arial' size='1' color='navy'>$row[6]</font>");
                  print 
    "</td>";
                  print 
    "</tr>";
                  print 
    "<tr>";
                  print 
    "<td align='left'>";
                  
    printf ("%.130s...""<font face='arial' color='blue' size='1'><a href='$row[4]'>http://store.whmx.com/$row[4]</a></font>");
                  print 
    "</td>";
                  print 
    "</tr>";
                  print 
    "</table><hr color='orange' width='97%'>";
            }
        }else{
            echo 
    "<font face='arial' size='3' color='navy'><center><b>No Results found for your search:</b> <em>$q</em></center></font>";
        }
    }
    ?>

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    thanks... that worked


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •