Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
pezzer
New Member
New Member



Joined: Nov 28, 2007
Posts: 10

PostPosted: Tue Apr 01, 2008 3:27 pm Reply with quote

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?
 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Tue Apr 01, 2008 5:30 pm Reply with quote

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 
View user's profile Send private message
pezzer







PostPosted: Tue Apr 01, 2008 6:40 pm Reply with quote

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. Very Happy
 
gregexp
The Mouse Is Extension Of Arm



Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol

PostPosted: Tue Apr 01, 2008 6:57 pm Reply with quote

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!! 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©