Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: if statement echoing both 'if' and 'else'?

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

    Unhappy

    this is proving tougher than i thought! i have tried allsorts but nothing is working.

    this is what i have now:
    PHP Code:
    if ($fris['friendname'] != $req_user_info['username']){ //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>";
        }
        else{
            echo 
    "[<font color='#666666'>You are friends</font>]";
        } 
    problem with this is, it echoes 'you are friends' with one of my friends, and the option to add as friend with the rest of my friends. its like the query isnt selecting all from table but query looks ok, here it is:
    PHP Code:
    $get mysql_query'SELECT * FROM `friends` WHERE `username` =  \''.$username.'\''); //gets friends
    $fris mysql_fetch_array($get); 
    anybody got any ideas?

  2. #12
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    echo the results
    Corrections to my coding/thoughts welcome.

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

    Default

    i tried echoing $fris and $fris['friendname'] and both no results. all i want to do is select all the friend name column from table friends where the session username is in column 'username'

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

    Default

    i dunno if this is anything to do with it, but i am trying to achieve this within an existing else thingy

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

    Default

    no worries guys, i finally sussed it

    now i have this:
    PHP Code:
    $getFriends mysql_query("SELECT * FROM `friends` WHERE `friendname` = \"".$req_user_info['username']."\" AND `username` = \"".$session->username."\"");
    if (
    mysql_num_rows($getFriends) == 0){ 
       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>";
      } 
     else {
        echo ( 
    "<br>[<font color='#666666'>You are friends</font>]<br>");

    thanx for all your help anyway

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
  •