Results 1 to 2 of 2

Thread: help with 'elseif' statement

  1. #1
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Post help with 'elseif' statement

    i been trying for the first time to insert an 'elseif' statement, but having trouble.

    this is my code:
    PHP Code:
    $getRequests mysql_query("SELECT * FROM `friend_requests` WHERE `username` = \"".$req_user_info['username']."\" AND `by` = \"".$session->username."\"");//gets requests
    $getFriends mysql_query("SELECT * FROM `friends` WHERE `friendname` = \"".$req_user_info['username']."\" AND `username` = \"".$session->username."\"");//gets friends
    if (mysql_num_rows($getFriends) == 0){ //checks if user isnt a friend
       
    echo "<a href=\"friendrequest.php?user=".$req_user_info['username']."\" title=\"Become Friends With ".$req_user_info['username']."\"><img src=\"friends_icon.png\" width=\"25\" height=\"25\" border=\"0\" /></a><br>";
    }
      elseif(
    mysql_num_rows($getRequests) => 0){ //checks for existing requests
      
    echo "request pending";
      }
      else{
          echo ( 
    "<br>[<font color='#666666'>You are friends</font>]<br>");
          } 
    all i get is a blank error screen, any ideas? thanx
    Last edited by liamallan; 04-26-2010 at 06:32 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There are a few problems:

    1. => is a different operator (assigning a relationship between variables like in a foreach() loop). You want to use >=.
    2. In this case, I don't see why you'd want "greater than or equal to" and not just "greater than" because you already have an if for when it is 0. So I'd just use >0.
    3. You should turn on error reporting in php.ini or set it manually when you're debugging. Google "php error reporting" or look at the various methods on php.net. It's a bit hard to find the information and even harder to explain it here, because there are many ways to do it and it depends on what kind of access you have to the server. But however you do it, use error reporting! Blank error screens are difficult to work with.

    Beyond that, I don't see anything wrong.

    Remember that elseif is an unusual construction because it removes complexity from the layers of code:
    PHP Code:
    //regular if and else statements:
    if (...) {
       ...;
    }
    else {
       if (...) {
          ...;
       }
       else {
          if (...) {
             ...;
          }
          else {
             ...........
          }
       }
    }


    ///using elseif or else if:
    if (...) {
       ...;
    }
    elseif (...) {
       ...;
    }
    elseif (...) {
       ...;
    }
    else {
       ........

    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    liamallan (04-26-2010)

Bookmarks

Posting Permissions

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