Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.