OK so I just finished off a basic site for client that has a custom CMS and includes news entries and submissions for a contest they are holding. They just threw a curveball at me and asked for a region/country selector as a splash page.
Turns out, they need to filter their content by 2 separate countries (US and EUROPE). Luckily it's only those 2 countries. So the obvious is I'm going to have to add a country code type row in all the tables of my db so each news entry and submission can be filtered..
I just wanted to get some input on what you guys think might be the best route to go about adding these new sessions with a site that's pretty much already built and structured a certain way: do I add the country row to all tables in my DB and go through all the PHP and add a bunch of new if/else statements to echo out each country's data? Or do I jimmy-rig the whole setup and just duplicate my site and have US have it's own site version with all PHP pulling US data, and EUR have it's own site version and pulling only EUR data.
Just want to see what others would do in this situation. Thanks in advance!
ADVICE ON ADDING A COUNTRY SELECTOR
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: ADVICE ON ADDING A COUNTRY SELECTOR
Little things like this are always best to try and discover early in the game, but sometimes clients just don't realize they need it until beta-launch.
In anycase, I would add a 'id_region' field to the table of interest. Create a table called 'regions' with the following fields:
Add as many regions as you want to the table and use this table to populate the combobox or whatever you offer visitors to select a region.
In the SQL query or wherever you construct it, you will need to add conditional tests, like this:
By default, if no region is selected all records will be shown. If a user selects a region, they will be shown filtered results. If you need two or more regions filtered, thats a different ball game but can typically be achived with a simple IN() clause.
If you effectively abstract the SQL in a gateway or data access layer, this change is trivial. If you have not done so, you are looking at a bit of manual labour. Havefun.
Cheers,
Alex
In anycase, I would add a 'id_region' field to the table of interest. Create a table called 'regions' with the following fields:
Code: Select all
regions:
id_primary, nameIn the SQL query or wherever you construct it, you will need to add conditional tests, like this:
Code: Select all
$sql = "SELECT * FROM table";
$id_region = (int)$_GET['id_region'];
if($id_region > 0){
$sql = "$sql WHERE id_region = $id_region";
}If you effectively abstract the SQL in a gateway or data access layer, this change is trivial. If you have not done so, you are looking at a bit of manual labour. Havefun.
Cheers,
Alex
Re: ADVICE ON ADDING A COUNTRY SELECTOR
Hmm, what about if I just inserted a "region" row into each table that needed their region defined (in my case: news entries and submissions) ?
From there I would use sessions and log a session as either US or EUROPE (the 2 regions the client wants). From there I could just run a bunch of if/else statements to display the same queries but with each region. It'll be a lot of repetitive code but would this work as well or should I avoid this?
From there I would use sessions and log a session as either US or EUROPE (the 2 regions the client wants). From there I could just run a bunch of if/else statements to display the same queries but with each region. It'll be a lot of repetitive code but would this work as well or should I avoid this?