Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/36070-sql-problem/
Share on other sites

[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.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/36070-sql-problem/#findComment-171215
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.