Take the 2-minute tour ×

I'm wanting to use a pair of query strings to generate specific page content

query string example: example.co.uk/index.php?brand=apple&video=red

I've managed to use some simple PHP to replace the div id's with query brand with some help as follows:

$recognised_brands = array( 
  // etc 

$default_brand = $recognised_brands[0]; // use first from list arbitrarily. 

$brand_to_use = isset($_GET['brand']) && in_array($_GET['brand'], $recognised_brands) 
  ? $_GET['brand'] 
  : $default_brand; 

echo '<div id="' . $brand_to_use . '"></div>';  

However I'm unsure on how to do similar for the second query called video.

If for example they query is ?brand=apple&video=red

Then I'd want to replace the video var in the page code to the correct number for red but I don't know how to add a list of these variables based on the video query like: red => 1 which then echo's 1 into the correct area?

Also based on the video selected I'd like part of the heading text to change and a paragraph of code below it but also unsure on where is best to specify this:

To try and clarify:

I have my brand query sorted I need to make my video query populate multiple areas headings, video id and content div's but not sure how!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

If I understood your question correctly, this would do what you are looking for:

$videoToNum = array("red" => 1, 
                    "blue" => 2, 
                    "yellow" => 3);

$videoValue = ((isset($_GET['video']) && isset($videoToNum[$_GET['video']])) ? $videoToNum[$_GET['video']] : null);

if($videoValue) {
    echo '<div id="' . $videoValue . '"></div>';  

The question is rather vague though, so you may want to elaborate further if this doesn't help.

Edit: Here's an example of a switch as discussed in the comments:

$video = (isset($_GET['video']) ? $_GET['video'] : null);

if($video) {
    switch($video) {
        case "red":
            //do red stuff
        case "blue":
            //do blue stuff
        case "yellow":
            //do yellow stuff
share|improve this answer
That's how I read his question, too. +1 –  davidethell Jul 13 '12 at 13:21
Hi David thank you - sorry I'm struggling with how to write this: OK so I have branding working and now with your code I can use this to select the correct video var number so if the query says red it can replace the var number 1 for eg. however also for the query red I need to replace part of a heading text area and insert a div with content further down the page - but don't know how to reference that on the page –  user1523591 Jul 13 '12 at 13:33
Perhaps you are looking for a switch statement? See edit –  Mahn Jul 13 '12 at 13:40
Thanks Mahn - I'm not sure - I just need red to do multiple things in multiple places: ie IF red: replace heading area insert div content replace video var and then the same needs to be for blue and yellow? –  user1523591 Jul 13 '12 at 13:42
So a switch should do... you put everything you need to change depending on the video variable inside the each block of the switch. (again, see the edit of the question) –  Mahn Jul 13 '12 at 13:43
show 8 more comments

Your Answer


