Forum Moderators: open

Message Too Old, No Replies

More fields or more code?

What is the tradeoff between table size and code efficiency?

         

sawatkins

4:30 pm on Apr 2, 2007 (gmt 0)

10+ Year Member



I'm building a calendar app for a client using PHP and MySQL.

Each day's events require 12 shifts to be covered per location (currently 2). That's 372 fields (times at least two), month after month. Currently the company employs less than 100 employees, so we're not talking about a huge volume of transactions, but they will be checking and rearranging their shifts often throughout the month. Shift times are set in stone, and to indicate that a shift is taken, the employee's 5 digit employeeid will be entered into that slot.

So here's my question. Is it better to have that many fields in each table or is it better to have, say 31 fields (one for each day of the monthy) and have shifts for each day separated by a comma, and use PHP to split and read each separate shift.

Btw, mods, if you think this is a question better suited for the PHP section, say so, or move it. Thanks.

Gus

justageek

5:10 pm on Apr 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



separated by a comma, and use PHP to split and read each separate shift
- Don't do it!

No that we go that thought out of the way...

It sounds like you just need to have a few relational tables since it looks like you are trying to keep everything in just one table. At a minimum split up the days, shifts and employees (I'm guessing employees is already) into separate tables and relate them. So each day would have an id that each shift can relate to and each shift can have an id that each employee relates to. That'll keep it small and fast.

JAG

joelgreen

5:12 pm on Apr 2, 2007 (gmt 0)

10+ Year Member



It depends on your needs. If you want to select/order by each separate shift then put them into separate fields. If shifts are for info only then you could put them inside one field.

BTW, I never saw a table which would have 3xx fields. Would advise to think over your database structure. Maybe it would be better to split this into few tables.