[thelist] one more PHP question - using a function

Tom Dell'Aringa pixelmech at gmail.com
Mon Oct 15 12:20:37 CDT 2007

On 10/15/07, Matt Slocum <matt.slocum at gmail.com> wrote:
> Tom, I'm not sure I understand your question.
> This is what I do. When it comes to php flow. I would avoid having long
> chunks of code running outside a function. I recommend separating each
> segment of a page into its own function.
> checkUser()
> printMenu()
> printOptions()
> printChart()
> printFooter()
> etc...
> At the begging of the php use conditional statements to control which
> workflow gets done.
> Is that even close to your question???

Close yes. Let me give a bit more context, maybe I am making this too hard.

Page lists out lists of races held in various places via a database query.
This just happens loosely at the beginning of the page.

For each item in the list, a link is written out which you click on to get
the full information about the race. This link is formatted events.php?id=4
for example.

Clicking the link gives you the info on the right side of the page on page

Ok, so when the page loads I am checking to see if the id is empty or not.
If it is, then we are at the first entrance of the page (or you got a bad
link in the race list with no id). If it is empty, I essentially skip the
whole process of pulling the race detail with an if statement like so:

       get the race detail

This works, but leaves an awkward blank space below 'race details' on
initial page load. At first I put an else clause and just wrote out
something like "please choose a race" but that doesn't work if they choose a
race that has no id for some reason - the message "choose a race" wouldn't
make sense, because they just had.

Basically I'm just trying to figure out the best way to handle that scenario
- tell them to choose a race on initial page load, and also have an
intelligent error message if they choose a race but for some reason it has
no ID.


More information about the thelist mailing list