case '5s':
include "iphoneModel.php";
break;
.....
case 's5':
include "samsungModel.php";
break;
case 's6':
include "samsungModel.php";
break;
.....
default:
include "model.php";
break;
}
[/php]
this is the url on the other page also
model.php?model=$model'
im probably going about this all wrong, but a kick in the right direction will be much appreciated.
If any further explanations are needed hit me up and ill do my best to explain
Unless this is a programming exercise to use a switch statement, you wouldn’t do it this way. A switch statement would be used when you have DIFFERENT processing to do based on a value. If all you are doing is matching an input value to an output value, you would use a data driven design, where you have the values stored in a data structure (preferably a database table, but an array would work for a smaller set of data), then you would just use the input value to find and retrieve the corresponding output value. By using a data driven design, you would not need to write out program logic for each possible value, only add the input/output mapping to the data structure. The php code would be simple and would not change as the amount of data changes.
// define a data structure that maps an input value (the array key/index) to an output value
$data_map = [];
$data_map[‘input_value_1’] = ‘output value 1’;
$data_map[‘input_value_2’] = ‘output value 2’;
$data_map[‘input_value_3’] = ‘output value 3’;
$data_map[‘input_value_4’] = ‘output value 4’;
// add other elements as needed
// get the input or a default value if there is no input
$model = isset($_GET[‘model’]) ? $_GET[‘model’] : ‘default input value’;
// get the output value or the default output value if there is no matching data
$output = isset($data_map[$model]) ? $data_map[$model] : ‘default output value’;
// done - $output contains the correct output value or the default output value[/php]
This only addresses the most immediate issue of not writing out block after block of logic that only differs in the values being operated on.
You would apply this same concept to your different web pages, that (should) all have the same layout, but only differ in the content being displayed. You need to have a single page layout/template that you dynamically populate with the selected content, specified by get parameter(s,)
[member=87768]phdr[/member] has you on the right track.
Where is the content coming from? Toss it into a database and use the model as a key. The database returns the differing content to a template page. Takes a handful of pages, if you don’t go the MVC route.
Appologies for a 6 day length since replying. Came down with a cold and couldn’t be bothered to do this website.
So essentially I have done the long and stupid way of doing this site.
Should I just start again with as mentioned by [member=87768]phdr[/member] with a template page and use the array to populate this template using the $_GET?
correct me if I am wrong, still getting over the cold, but running up to the deadline of this site.
Thanks [member=46186]Kevin Rubio[/member] having a sift through now, and looking fairly simple. seem to remember this was how we did things at an old job.
Will try and have a go at structuring my site this way