Efficiency in MySQL queries - which is better?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
real_mccoy
Forum Newbie
Posts: 2
Joined: Thu Mar 30, 2006 4:22 am

Efficiency in MySQL queries - which is better?

Post by real_mccoy »

Hi Folks,
I have been using PHP/MySQL for a couple of years now, and am attempting to develop a "program guide", which lists radio or tv programs in a weekly schedule. The issue I am facing is this: I have decided to have each weekday as a field in the table, and if the program occurs on multiple days, those days will have the value "Y". When I go to display the program guide, I am wondering if I should:
A. pull all of the data out of the table and iterate through it multiple times, in order to display each day's programs consecutively - OR
B. conduct seven separate queries on the table, only pulling items which are marked for each day to display (i.e., "where Mon = 'Y'").

All told, there will only be about 100 items at most in the table, so it won't be a huge hit anyway. I'm just wondering what the most efficient way is to do it.

Opinons?

thanks in advance...
jrd
Forum Commoner
Posts: 53
Joined: Tue Mar 14, 2006 1:30 am

Post by jrd »

I would rather do the latter, A.
real_mccoy
Forum Newbie
Posts: 2
Joined: Thu Mar 30, 2006 4:22 am

Er..... the latter would be B, the former would be A

Post by real_mccoy »

You mean you'd rather do the first one? I was thinking I'd rather do that, too, but am a little stumped as to how to iterate through and pick out each day's programs... once I've picked out all of Monday's programs, for instance, I then need to go through the results again and pick out Tuesday's, then ditto for Wednesday's, etc., etc. I just wonder if that's not more inefficient than seven small hits on the database...

What do you think?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Efficiency in MySQL queries - which is better?

Post by Roja »

real_mccoy wrote: All told, there will only be about 100 items at most in the table, so it won't be a huge hit anyway. I'm just wondering what the most efficient way is to do it.
Depends on the table, the data, the mysql settings, the OS settings, and more.

Test in your environment, and find out.
Post Reply