Exclude a cat_id in this SQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

Exclude a cat_id in this SQL

Post by danjapro »

I am not the best at sql and php, but.
I am easier with .net apps and sql query.

How do you include or exlude a specific list of items based on a set id like "cat_id", exlude specifi cat_id?

What is correct way to write it?

Code: Select all

	$db	 =& JFactory::getDBO();
	
	$query  = "	SELECT
							* 
					FROM
							".$db->nameQuote('#__community_videos')."
					WHERE
							".$db->nameQuote('published')."=".$db->quote(1)."
					AND
							".$db->nameQuote('permissions')."=".$db->quote(0)."
					AND NOT
						                ".$db->nameQuote('cat_id')."=".$db->quote(5)."
																																								
					ORDER BY
							".$db->nameQuote('created')." DESC
					LIMIT 
							".$limit;

	$db->setQuery( $query );
	
	$result = $db->loadObjectList();






User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Exclude a cat_id in this SQL

Post by social_experiment »

Wouldn't it be easier to use the not equal operator (!=) ?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply