Ok,
I might as well explain what exactly i am trying to do, then maybe you guys can explain a better method.
Right, i have a Comments table:
Comments
CMid
CMHid
CMPid
CMUid
CMcomment
CMdateadded
CMdeleted
Each comment can be linked to 10 different tables:
ConfPaper, JournalArticle, EdBookChapter, Thesis, Patent, Monograph, Unpublished, Misc, Website, TechReport
Each table contains different information, and holds documents.
Now each of these 10 tables have a “Pid” which is how the Comments table JOINS onto it by CMHid.
I need to basically retrieve which record has been commented on FROM WHICH table.
So a typical set of records in the Comments table can be as such:
CMid - 2 (Unique, AutoIncr)
CMHid - 1 (Which Table from the 10 it belongs to)
CMPid - 13 (ID of record from the 10 tables)
CMUid - 1 (User ID)
CMcomment - This is a comment
CMdateadded - 2010-07-26 15:05:31
CMdeleted - 0
So to do this i was thinking of doing something like this:
public function selectAllComments($tablename, $tableID){
$query = "SELECT * FROM Comments c
LEFT JOIN Category ct ON c.CMHid = ct.CTid
LEFT JOIN Users u ON u.Uid = c.CMUid
LEFT JOIN ConfPaper t ON t.Pid = c.CMHid
WHERE c.CMdeleted = 0 AND c.CMHid = 1
GROUP BY c.CMcomment
ORDER BY c.CMdateadded DESC";
return mysql_query($query);
}
Category is a list of categories for each of the 10 tables, the Pid in each table represents which category it belongs to.
So now with the form i am trying to retrieve which table name AND the ID of the table:
<form method="get" action="">
<label>Search by type: </label>
<select name="c" id="c">
<? while($row = mysql_fetch_object($category)):
echo "<option value=\\"$row->CTname\\">$row->CTname</option>";
endwhile;
?>
</select>
<input type="submit" id="submit" value="Search"/>
</form>
Now firstly, is my method even the correct way to do this?
How can i achieve what i am trying to do?
Thanks