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 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question the IF statement?

    I have used the following code to do 2 things:

    1: if no data is entered into my search boxes then a reply is printed.
    2: if correct data is entered into my serach it returns the result.

    I would also like it to return a reply if no data is found by the search, I have tried alsorts but can't seem to combine the three without having the reply show on both the result data and the not found data.


    $Query = "SELECT * from $TableName where category LIKE '%$_GET[category1]%'";
    $Result = mysql_db_query ($DBName, $Query, $Link);
    if (empty($_GET['category1']) and empty ($_GET['business1'])) {
    print ("<BR>\n");
    print ("Sorry, no data found<BR>\n");
    } else while ($Row = mysql_fetch_array ($Result)) {
    print ("<BR>\n");
    print ("<b>$Row[businessname]</b><BR>\n");
    print ("$Row[addressline1], $Row[addressline2] $Row[village]<BR>\n");
    print (ucfirst("$Row[town]<BR>\n"));
    print (ucfirst("$Row[county]<BR>\n"));
    print (strtoupper("$Row[postcode]<BR>\n"));
    print ("<b>T:</b> $Row[telephone]<BR>\n");
    print ("<b>F:</b> $Row[fax]<BR>\n");
    print ("<b>E:</b> <a href=mailto:$Row[email]>$Row[email]</a><BR>\n");
    print ("<a target=_blank href=http://$Row[website]>$Row[website]</a><BR>\n");
    print ("<b>Category:</b> $Row[category]<BR>\n");
    print ("<b>Features:</b> $Row[feature1] • $Row[feature2]<BR>\n");
    print ("----------------------------------------------------------------\n");
    }


    Please if you can help get in touch

    Cooper


  • #2
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts
    have you tried adding this to your script?
    Code:
    $rows=mysql_num_rows();
    if(!$rows){ echo "No Results Found, Please Enter Another Search String";}
    else { 
    The rest of your script 
    
    
    }

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use elseif
    http://uk2.php.net/elseif

    Also when posting code in the forums it's handy to put it in PHP or CODE tags.

    PHP Code:
    <?php
    echo 'This is php code';
    ?>

  • #4
    New Coder
    Join Date
    Jan 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Warning: Wrong parameter count for mysql_num_rows() in

    I keep getting this erroe message ... any ideas why?

    Cheers

    Cooper

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://uk2.php.net/mysql_num_rows

    You need to query something
    PHP Code:
    $rows=mysql_num_rows($Result); 

  • #6
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, I was in a hurry and forgot to put that in.

  • #7
    New Coder
    Join Date
    Jan 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Guys, all sorted now.

    Many Thanks

    Cooper


  •  

    Posting Permissions

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