[Sussex] Any PHP gurus coming tonight?

Mark Harrison Mark at ascentium.co.uk
Thu Nov 27 14:04:00 UTC 2003


Any PHP experts coming tonight who might be able to sit down for 10 minutes
and tell me how to code something more efficiently???

Regards,

Mark
-------

Detailed version follows:

I've had one of those "oh, bother" moments this afternoon.

The code I've got WORKS, but I can't help feel that it needs some efficiency
optimisation. I can see, at an algorithmic level, what I should have done
instead, but how to implement it in PHP is taxing me.)

I'm designing a fairly basic interactive site, intended for use on a REALLY
DUMB touchscreen web terminal, this morning. It's a canteen system for a
small client, and database driven for both users and items. Because of
client-side restrictions, I've got to assume next to no client-side
processing capability, and because it's intended for use with fingers rather
than pointers, I _can't_ use fiddly UI items like input boxes.

So, once the user has selected their name from a list, they get presented
with a page that has 12 items on the menu, showing the price of each, and
the number they have eaten (initially all the numbers are 0).

Then, they press the PICTURE of the item to indicate that they've had one
more....I call a new URL with the number of items selected embedded into the
URL...

eg - the initial URL might be:
http://localhost/selection.php?Number=101&I1=0&I2=0&I3=0&I4=0&I5=0&I6=0&I7=0&I8=0&I9=0&I10=0&I11=0&I12=0&StaffName=Johnson,
Brian

Then, the act of pressing the picture of the can of coke (item number 5),
take them to
http://localhost/selection.php?Number=101&I1=0&I2=0&I3=0&I4=0&I5=5&I6=0&I7=0&I8=0&I9=0&I10=0&I11=0&I12=0&StaffName=Johnson,
Brian

Now, the code works, but I wrote the inner database loop (to look up things
like prices/descriptions/pointers to images) just for the first item, which
includes a SQL call...

... then I copied/pasted that code 12 times, changing five things by hand...
which now means 12 SQL calls per page... Actually, performance is adequate,
but it feels wildly inelegant an unscalable.

I really could do with a PHP expert to explain some things - I'm still
getting to grips with multiple levels of variable indirection... and I'm
sure that's the way to handle this.

Regards,

Mark





More information about the Sussex mailing list