I have had a long problem with this code. I have posted this question multiple times on SOF but never was able to clearly state the problem but now i can.
I want to be able to see posts by other agents for my clients. So in this query i shouldn’t be able to see the posts added by me for my clients but posts for my clients added by other agents. Below is what i have been trying. The good thing is that the code does what i need to but then it shows me posts that are not for my clients too. So i am not sure where I need to make the tweak?
Code:
$type1 = "Added by Other Agents"
$myuserid = My id. So i am using <> to not show posts added by me for my clients.
$sql = "SELECT posts.posts_id, accounts.full_name,
agents.agent_name, posts.person_id, posts.why_posts,
posts.just_date, posts.type, posts.date_time_added FROM
posts LEFT JOIN accounts ON posts.person_id = accounts.person_id
LEFT JOIN agents on posts.agent_whois = agents.agent_id WHERE
(posts.type = '$type1') and
(posts.added_by <> '$myuserid')";
$result=mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{
$postsid = $row['posts_id'];
$agentwho = $row['person_id'];
$agentname = $row['agent_name'];
$reason = $row['why_posts'];
$datetimeadded = $row['just_date'];
$name = $row['full_name'];
$type = $row['type'];
print("");
}
}
If the accounts table stores which agent is associated with a client, then you need to add an additional condition to specify accounts that are only associated to you. Since it is still unclear to me which field that is, let’s say it’s called
accounts.agent_ownerIn this part of your SQL:
Add: