homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Need Help With Hidden Results

 4:27 pm on Jan 7, 2010 (gmt 0)

I have a custom news blog I set up for where I work but I am having a problem. I have a field for each news article entry in the database called 'activated'. The value is either 0 or 1, for on or off of course. The problem is, i have the db set to spit out three stories a page. The page though that the hidden story would appear on were it not to be skipped by a 'continue' statement in the while($row) loop. I am trying to figure out how to get my query to see these results and not count them in the three articles that will actually be on the page. I am stumped guys. Anyone have a little insight?



 4:37 pm on Jan 7, 2010 (gmt 0)

If you're not going to display the stories, then why don't you just exclude them from the query in the first place?


 5:04 pm on Jan 7, 2010 (gmt 0)

The thing is, the script has to pull the value for the activated field to know it is not supposed to show it. I think you may have given me some inspiration though. I am going to before executing the main query, execute one to check for hidden stories on that page. For every hidden story it finds, by way of the 'activated' field switch, I will have it +1 to the limit of the query. Does someone want to tell me if there is a more efficient way, or is that about how I should go?


 5:25 pm on Jan 7, 2010 (gmt 0)

There shouldn't be any reason why you need to have PHP skip the unactivated posts. MySQL can do it in the query before it even gets to PHP:

SELECT * FROM `article` WHERE `activated` = 1


 5:30 pm on Jan 7, 2010 (gmt 0)

Ah duh! Hahaha this is my third year of PHP and sometimes my mind starts thinking way complicated instead of simple. Wow, thanks guys. Sorry about that I feel like a dunce!


 5:45 pm on Jan 7, 2010 (gmt 0)

No worries. :)

I used to do all sorts of manipulation of MySQL data in PHP code. But one of the early things I learned on WebmasterWorld that I always remember is "MySQL is a database engine, PHP isn't." You should always try to push anything to do with slicing, dicing, or sorting data to MySQL.


 9:43 pm on Jan 7, 2010 (gmt 0)

That is good advice, i'll keep that in mind. Thank you so much for your help.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved