smc Posted January 28, 2007 Share Posted January 28, 2007 Hello,Okay heres the deal. Basically I have a front page on my news CMS. On this page are 4 categories, News, Features, Entertainment, and Sports. Each category has 2 table blocks underneath it.What I need is a MySQL function that will fetch the latest two stories in that category group and then return them to the PHP script for proccessing. The additional catch is that I need it to not take into account records that in my database have "pending" or "rejected" in their status list.My database is set up with the table stories, and under that the article name, author, category, status, etc.I tarted trying $query = mysql_query (" SELECT * FROM stories WHERE category = '$news' LIMIT 0,1 ") but that doesn't take into account the status, and would only return one entry reguardless of it's status.Thanks for any light you can shed on my problem Quote Link to comment https://forums.phpfreaks.com/topic/36070-sql-problem/ Share on other sites More sharing options...
nfr Posted January 28, 2007 Share Posted January 28, 2007 SELECT * FROM stories WHERE (((category = '$news') and ((status != "pending") or (status != "rejected"))) order by article_id desc limit 2;Something like that, you mean?Regards,Neil. Quote Link to comment https://forums.phpfreaks.com/topic/36070-sql-problem/#findComment-171206 Share on other sites More sharing options...
HuggieBear Posted January 28, 2007 Share Posted January 28, 2007 [quote author=nfr link=topic=124419.msg515462#msg515462 date=1170002320]SELECT * FROM stories WHERE (((category = '$news') and ((status != "pending") or (status != "rejected"))) order by article_id desc limit 2;Neil.[/quote]Shouldn't that be...[code]SELECT * FROM stories WHERE category = '$news' AND status != 'pending' AND status != 'rejected' ORDER BY article_id DESC LIMIT 2;[/code]I changed the OR code, I think that will return spurious results.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/36070-sql-problem/#findComment-171215 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.