Peter have sent request to Michelle by clicking “add friend” button on Michelle’s page, database table tbl_frienRequest store Peter at “user” and store Michelle at “targetuser”.
Now Peter’s page must not show the “add friend” button when Michelle visiting Peter’s page. Michelle’s page also must not show “add friend” button when Peter visiting Michelle page.
How to write if else statement to show or not show the “add friend” button on their pages?
Currently I am using this method :
$query111 = "SELECT id FROM tbl_frienRequest WHERE user='{$username1}' AND targetuser='{$username2}'";
$result111 = mysql_query($query111,$connection) or die (mysql_error());
confirm_query($result111);
$requestCount = mysql_num_rows($result111);
$query2 = "SELECT id FROM tbl_frienRequest WHERE user='{$username2}' AND targetuser='{$username1}'";
$result2 = mysql_query($query2,$connection) or die (mysql_error());
confirm_query($result2);
$requestCount2 = mysql_num_rows($result2);
if (($requestCount == 0) or ($requestCount2 == 0)){
//show "add friend" button.
}
I think it works but the codes is very long, is there any other shorten codes to get the same output?
You can use an OR condition in your query:
i.e:
Try this: