Design for an online car configurator in PHP

Hi,

Essentially I know the theory for working in PHP, SQL, HTML, Sessions, etc. However, what I am missing is connecting the dots most efficiently.

I am trying to build a very simple online car configurator. The flow is:

  • user picks a brand
  • depending on the previous choice, user is presented with models, user picks one
  • depending on the previous choice, user is presented with model lines, user picks one
  • depending on the previous choice, user is presented with engines, user picks one
  • depending on the previous choice, user is presented with options, user picks 0-n options
  • user can submit a form that generates an email with all of the previously chosen options.

My current “design” works. But it is very nasty to maintain and I am sure there are better ways of going about it.

  • I have a single, monolithic PHP file where everything happens. I don’t use any classes or functions. I don’t use AJAX.
  • Roughly the steps are as follows:
  1. Start session, check the phase the user is in by looking at what has been set already in the session E.g. if user has already selected a brand, models must be shown etc.
  2. SQL statement depending on phase, is executed to show all relevant items for that phase within the same PHP file.
  3. When a user clicks on any item, they simply call the same PHP page via GET (e.g. ?BrandID=2).
  4. That value is then stored into the same session.
  5. got to 1. for the other items.
  • My session variables are very simple and unstructured: $_SESSION[‘BrandID’], $_SESSION[‘ModelID’], etc.

I know this is a weird and sort of generic question. But I would love to know what the best practices are of how to structure this whole thing. How would you structure it?

  • should I use classes for the sessions, SQL queries, etc.?
  • Is there a better way than to use GET?
  • Should I have the SQL queries and or session logic defined in a separate file/function/class?

Input is greatly appreciated. Cheers!

Best regards,
Hans

(IMO)
The system you’re using has way too many page loads - one for every selection - I know we’re in the broadband age now, but still…

I’d go with javascript (ajax/jquery/etc.) to populate the boxes then record everything at the end when you have whittled it down to correct specs. I use a similar system on one of my sites for timezones and the time you’ll save eliminating page reloads, will be appreciated by the user.

Just my two-pence worth…
Cheers,
Red. :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service