Jump to content

IF Statement in query


Stooney

Recommended Posts

This is tough to explain.  I am trying to squeeze two things into one query.  Originally the query simply did a search for files based a criteria, easy.  What I'm trying to integrate into the same query is to check whether or not the file_id of each file that fits the criteria is entered in another table (highlights) and associated with the users' user_id. 

 

So the highlights table looks like this:

highlight_id - user_id - file_id

 

The highlights table just records when a user downloads a file.  The whole point of this query is to search files based on the criteria (working already) and set the outputs tr (table row) to the correct class (highlight or no highlight).

 

So in the end all this query is for is to search for files and know when to highlight or not hightlight a file.  A file that has not been downloaded (not yet in the highlights table) should be highlighted.

 

Here is what I have so far, the IF statement isn't all there because I know it's wrong.  The necessary part is there though.

 

<?php
$query="SELECT 
f.file_id, 
f.file_size, 
f.file_dname, 
CONCAT(u.user_fname, ', ', u.user_lname) as tname, 
CONCAT(c.client_fname, ', ', c.client_lname) as cname, 
IF((**STUCK HERE**)>0, 1, 0) as hl 
FROM
	".CLIENT_FILES." as f, 
	".USERS." as u, 
	".CLIENTS." as c 
WHERE 
	".$q." AND
	f.client_id=c.client_id AND
	u.user_id=c.user_id
ORDER BY 
	f.file_dateadded DESC";
?>

 

Hope I made sense, it's late -_-  Thank You.

 

EDIT:  MySQL 5

Link to comment
https://forums.phpfreaks.com/topic/155476-if-statement-in-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.