0

how show message if nothing to show from db message name "you dont have any friend" here is php code

$mid = mysql_real_escape_string($_COOKIE['member_id']);
$res = mysql_query("
SELECT profile_friends.friends_friend_id, members.name, profile_friends.friends_member_id,members.member_id,pp_main_photo,pp_photo_type
FROM profile_friends
INNER JOIN members
ON profile_friends.friends_friend_id=members.member_id
INNER JOIN profile_portal on pp_member_id = member_id
WHERE friends_member_id  = '$mid'");
while($row = mysql_fetch_array($res)){  
?>



<?php echo $row['name'];?>
<img src="../forum/uploads/<?php echo $row['pp_main_photo'];?>
" width="50" height="50" alt=""/><br>


<?php
}
?>
  • [`mysql_num_rows()`](http://php.net/manual/en/function.mysql-num-rows.php) -> `if(mysql_num_rows($res) == 0) echo "you dont have any friend"; else { while($row = mysql_fetch_array($res)){ ...` – Sean Sep 06 '14 at 13:37
  • Parse error: syntax error, unexpected T_IF, expecting T_STRING or T_VARIABLE or '{' or '$' in C:\AppServ\www\pages\about.php on line 24 mysql_num_rows() -> if(mysql_num_rows($res) == 0) echo "you dont have any friend"; else { while($row = mysql_fetch_array($res)){ – user2779438 Sep 06 '14 at 13:40
  • Did you include the closing `}` for the `else` -> `else { while($row = mysql_fetch_array($res)){ ...[your code]... } }`? – Sean Sep 06 '14 at 13:45
  • using your method i have error http://prntscr.com/4kai97 why? – user2779438 Sep 06 '14 at 18:43
  • The error is because you added `mysql_num_rows() ->` which was just my pointing out the php function to use, and it is a link to the function in the php docs. Remove `mysql_num_rows() ->`. Also, remove the outside `while($row = mysql_fetch_array($res)){}`. You only want to loop through `mysql_fetch_array()` if `mysql_num_rows($res) == 0`. – Sean Sep 06 '14 at 18:47

2 Answers2

0

The first comment is correct.

if (mysql_num_rows($res) < 1) {

   echo "no friends found";
} else {
    echo $row['name'];?>
    <img src="../forum/uploads/<?php echo $row['pp_main_photo'];
     ?>
   " width="50" height="50" alt=""/><br>

Also, the error you posted usually just means you missed a ; somewhere...

Chemdream
  • 618
  • 2
  • 9
  • 25
0

As stated in my comments, use mysql_num_rows() to check if > 0 loop through the results.

$mid = mysql_real_escape_string($_COOKIE['member_id']);
$res = mysql_query("
       SELECT profile_friends.friends_friend_id, members.name, profile_friends.friends_member_id,members.member_id,pp_main_photo,pp_photo_type
       FROM profile_friends
       INNER JOIN members
       ON profile_friends.friends_friend_id=members.member_id
       INNER JOIN profile_portal on pp_member_id = member_id
       WHERE friends_member_id  = '$mid'");

if(mysql_num_rows($res) == 0) 
     echo "you dont have any friend"; 
else {
    while($row = mysql_fetch_array($res)){  
?>
        <?php echo $row['name'];?>
        <img src="../forum/uploads/<?php echo $row['pp_main_photo'];?>" width="50" height="50" alt=""/><br>  
<?php
    }
}
?>
Sean
  • 12,443
  • 3
  • 29
  • 47