NYCPHP Meetup

[nycphp-talk] every other record

Rahmin Pavlovic rahmin at insite-out.com
Sun Feb 5 13:28:57 EST 2006


Hi,
First of, thanks to everyone for the responses -- especially to Carlos for
the clever SQL.  (Sorry if I've missed new posts, been away for a few days.)


On 2/1/06 5:36 PM, "Adam Maccabee Trachtenberg" <adam at trachtenberg.com>
wrote:

> I see many people have provided a number good of answers, so let me
> step back and ask: "What problem are you trying to solve?"


Alrighty.  Basically, we're redesigning a site that ultimately contains over
100k records (table a) that belong to over 300 sections (table b).  (Each
week, the editors will upload 50+ new records, which may or may not contain
new sections.)

The redesign is an all-CSS layout.  For the section landing page, we're
showing the 5 most recent records, followed by a two-column layout
displaying the next 30 or so.

Each 'column' is essentially a <div> block, so I want to show all even
records in the left block;  all odd records in the right.  (Editors can
choose sort-order, turn records on and off or simply display all in
reverse-cron, so accuracy is important.)  I've been playing around with SQL
to do this as I'd rather not put the weight on PHP.

(This is all working, BTW.)


> Why do you need every other row? Is this data likely to change? How
> often is it updated? Can you pre-compute an ENUM that you insert upon
> writing the table that lets you do:
> 
> SELECT * FROM TABLE WHERE filter = 'even';
> SELECT * FROM TABLE WHERE filter = 'odd';


See above for sorting rules, but I just want to say that a pet peeve of mine
is text-entries in the db for boolean logic.  Why not something like odd=0
|| odd=1?

The legacy site we're redesigning here actually had doNotShow='yes' ||
doNotShow='no' in the db.  I banged my head on the desk when I saw this.  It
not only takes more memory to retrieve & test the results, but the logic in
this case is in reverse.  Every time I'd look at a record, I'd have to ask
myself, "Do I not want to show the record?  No, I do not want to not show
it."

These are now display=1 || display=0.  It is far more easier to test:

if($record['display']) {}

Than it is:

if($record['doNotShow']=='no') {}


(Just had to get that off my chest..)





More information about the talk mailing list