Author |
Message |
pezzer
New Member


Joined: Nov 28, 2007
Posts: 10
|
Posted:
Tue Apr 01, 2008 3:27 pm |
|
Something like this is surely already mentioned somewhere here, but I can't find it, so...
I'm trying to exclude a specific category (and possible multiple categories) from the "Last 5 Articles" block. I tried to modify the sql query with no luck. I looked at other examples of WHERE statements, but I can't seem to make this one work as those are listed.
Here is the original line in the "block-Last_5_Articles.php" file.
Code:$sql = 'SELECT sid, title, comments, counter FROM '.$prefix.'_stories '.$querylang.' ORDER BY sid DESC LIMIT 0,5';
|
I modified it to this:
Code:$sql = 'SELECT sid, catid, title, comments, counter FROM '.$prefix.'_stories '.$querylang.' WHERE 'catid' !='4' ORDER BY sid DESC LIMIT 0,5';
|
I tried a few variations as well as trying to add escape characters in front of the ' but nothing worked. Something I didn't try because I don't quite understand it is to turn catid into $catid and do something with that.
Do I need to globally define catid and/or turn it into $catid?
Does anyone have any thoughts on how to make this work? |
|
|
|
 |
Gremmie
Former Moderator in Good Standing

Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA
|
Posted:
Tue Apr 01, 2008 5:30 pm |
|
Looks like you got your quotes messed up. Try this:
Code:
$sql = 'SELECT sid, catid, title, comments, counter FROM '.$prefix.'_stories '.$querylang.' WHERE catid != 4 ORDER BY sid DESC LIMIT 0,5';
|
This will probably fail if you have the $multilingual set to 1 also, because $querylang will already contain a WHERE clause. But if you don't, it should work. |
_________________ Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module |
|
|
 |
pezzer

|
Posted:
Tue Apr 01, 2008 6:40 pm |
|
Excellent. That worked perfectly. I think leaving the quotes off would have been the last thing I tried (and by far the simplest.)
Thank you - That will help tremendously...
So in 6 months or 2 years if I upgrade to a multilingual site, I am NEVER going to understand why my site is suddenly failing. I better leave myself a note right now.  |
|
|
|
 |
gregexp
The Mouse Is Extension Of Arm

Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol
|
Posted:
Tue Apr 01, 2008 6:57 pm |
|
just remember this, this is how I think of quotes:
$var2='second part of string';
$var='part of string'.$var2.'third part of string';
The dots tell it to add it to the string, I think of it as different parts, first quote begines the quote, the next quote ends it. So to tell php not to take it literally, we backslash it, If I wrote:
$var='don\'t walk the dog today';
The second quote, which is backslashed, isnt the end of the first part, the backslash tells php not to take it literally, but that it is actually a part of the
string. |
_________________ For those who stand shall NEVER fall and those who fall shall RISE once more!! |
|
 |
 |
|