I have encountered a “unique” problem. I have two tables, one for clients and second for their users. The third table is a comments table. So when a comment is added to the third table, the posting persons id and the organizations manager whom the comment is pertaining to, his id is stored. Now when i have to show the comments i am not sure how to get the appropriate names as they are stored in two different tables.
Any ideas on how to do this?
Some code that i manage to create:
$query="SELECT v_comments.v_comment_id, d_names.d_name,
v_comments.visit_reply, v_comments.just_date FROM v_comments
LEFT JOIN d_names ON v_comments.d_id = d_names.d_id
WHERE v_id = '$vid' and v_comments.s_id='$sid' ORDER BY v_comments.id DESC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "";
$i=0;
while ($i < $num) {
$reply=mysql_result($result,$i,"v_reply");
$replyid=mysql_result($result,$i,"v_comment_id");
$dname = mysql_result($result, $i, "d_name");
echo "";
echo "";
$i++;
}
Do you just need to add a join to the other table, and SELECT the other name field?
This should work if the other table is called “s_names” (I had to guess at that):