Welcome to WebmasterWorld Guest from 23.22.250.113

Forum Moderators: open

Message Too Old, No Replies

Need Help With Hidden Results

     

chasehx

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

5+ Year Member



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?

LifeinAsia

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

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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

chasehx

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

5+ Year Member



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?

whoisgregg

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

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

chasehx

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

5+ Year Member



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!

whoisgregg

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

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

chasehx

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

5+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month