in my site you can follow and unfollow some other user, i did that but I want now to give them the ability to a user (i have two types of users, doctor and patient) to see members of the other category. To make it more clear, i logged in as a doctor and i want to see all the users that belong to the patient table of my database, notice that doctor and patient belongs to differents tables of the database.
My code is this...
<?php
include_once 'header.php';
if (!$loggedin) die();
echo "<div class='main'>";
if (isset($_GET['view']))
{
$view = sanitizeString($_GET['view']);
if ($view == $username) $name = "Your";
else $name = "$view's";
echo "<h3>$name Profile</h3>";
/**
* Deixnoume to profil opws to exoume ftiaksei sto function.php
*/
showProfile($view);
echo "<a class='button' href='messages.php?view=$view'>" .
"View $name messages</a><br /><br />";
die("</div></body></html>");
}
/**
* This code is for showing the users while you are logged in as patient
*/
if("SELECT username FROM patient WHERE username='$username'")
{
if (isset($_GET['add']))
{
$add = sanitizeString($_GET['add']);
if (!mysql_num_rows(queryMysql("SELECT * FROM friends
WHERE username='$add' AND friend='$username'")))
queryMysql("INSERT INTO friends VALUES ('$add', '$username')");
}
elseif (isset($_GET['remove']))
{
$remove = sanitizeString($_GET['remove']);
queryMysql("DELETE FROM friends WHERE username='$remove' AND friend='$username'");
}
$result = queryMysql("SELECT username FROM doctor ORDER BY username");
$num = mysql_num_rows($result);
echo "<h3>Other Members</h3><ul>";
for ($j = 0 ; $j < $num ; ++$j)
{
$row = mysql_fetch_row($result);
if ($row[0] == $username) continue;
echo "<li><a href='members.php?view=$row[0]'>$row[0]</a>";
$follow = "follow";
$t1 = mysql_num_rows(queryMysql("SELECT * FROM friends
WHERE username='$row[0]' AND friend='$username'"));
$t2 = mysql_num_rows(queryMysql("SELECT * FROM friends
WHERE username='$username' AND friend='$row[0]'"));
if (($t1 + $t2) > 1) echo " ↔ is a mutual friend";
elseif ($t1) echo " ← you are following";
elseif ($t2) { echo " → is following you";
$follow = "recip"; }
if (!$t1) echo " [<a href='members.php?add=".$row[0] . "'>$follow</a>]";
else echo " [<a href='members.php?remove=".$row[0] . "'>drop</a>]";
}
}
/**
* This code is for showing the users while you are logged in as doctor
*/
elseif("SELECT username FROM doctor WHERE username='$username'")
{
if (isset($_GET['add']))
{
$add = sanitizeString($_GET['add']);
if (!mysql_num_rows(queryMysql("SELECT * FROM friends
WHERE username='$add' AND friend='$username'")))
queryMysql("INSERT INTO friends VALUES ('$add', '$username')");
}
elseif (isset($_GET['remove']))
{
$remove = sanitizeString($_GET['remove']);
queryMysql("DELETE FROM friends WHERE username='$remove' AND friend='$username'");
}
$result = queryMysql("SELECT username FROM patient ORDER BY username");
$num = mysql_num_rows($result);
echo "<h3>Other Members</h3><ul>";
for ($j = 0 ; $j < $num ; ++$j)
{
$row = mysql_fetch_row($result);
if ($row[0] == $username) continue;
echo "<li><a href='members.php?view=$row[0]'>$row[0]</a>";
$follow = "follow";
$t1 = mysql_num_rows(queryMysql("SELECT * FROM friends
WHERE username='$row[0]' AND friend='$username'"));
$t2 = mysql_num_rows(queryMysql("SELECT * FROM friends
WHERE username='$username' AND friend='$row[0]'"));
if (($t1 + $t2) > 1) echo " ↔ is a mutual friend";
elseif ($t1) echo " ← you are following";
elseif ($t2) { echo " → is following you";
$follow = "recip"; }
if (!$t1) echo " [<a href='members.php?add=".$row[0] . "'>$follow</a>]";
else echo " [<a href='members.php?remove=".$row[0] . "'>drop</a>]";
}
}
?>
<br /></div></body></html>
I did it for the patient but it does not show me the users which are patients when i am logged in as a doctor. I think there is a problem with the if
and the elseif
of my code but i cant find what. Can you help me?