I have these tables:
Report:
id, ip_addr, upload_id
Upload:
id, userID, name, location, category, private
Basically I am displaying all the uploads and I want to join the report table to determine if the current user's ip_address has reported the upload (I will compare ip_addr after query). The problem I am running into is that there can be multiple reports for the same upload, and by different people (not necessarily a registered user, which is why I am using the ip_addr). So how would I setup this MySQL query and how can I perform the following while in a loop..?
PHP: ($things would be the query result)
foreach((array)$things as $files){
if ($files['ip_addr'] == $user_ip_addr) {
// display upload info and an already reported image
} else {
// display upload info with an unreported image
}
}
So far I have this, which display all the uploads
$query = 'SELECT * FROM upload WHERE private="0" ';
Just have multiple identifiers. table structure would be similar to this:
Table 'reports'
reported_by = user id
reported_id = upload id
id = primary index
Your query could be like this:
SELECT COUNT(*) as `rows` WHERE reported_id = ? AND reported_by = ?
Et voila,
<?php
if($rows['rows'] > 0) // they reported it
echo 'Tattle tale.';
else
echo 'Snitches get stitches.';
?>
? are unnamed parameters (assuming you're using mysqli or pdo)