1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem passing values from array

Discussion in 'PHP' started by x3sphere, Oct 30, 2006.

  1. #1
    $feed = array (
    	'psp' => '7',
    	'ps3' => '9',
    	'xbox360' => '17',
    	'wii' => '14',
    	'nds' => '12',
    	'reviews' => '21',
    	'main' => '2,3,7,9,12,14,17'
    );
    
    if (isset($section)) {
    	$forumid = $feed[$section];
    } else {
    	$forumid = $feed['main'];
    }
    Code (markup):
    The $forumid is then passed onto a mysql query. Problem is, its only listening to the else statement. Its ignoring all other values in the array, say for example if section=psp is passed in the URL it will still output the main feed.

    I think the problem is the if statement, but not sure whats wrong. If I manually pass the $section var it works fine, so can't be the array or query.
     
    x3sphere, Oct 30, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Echo the $section then so you know why the if statement is failing to turn true.
     
    T0PS3O, Oct 30, 2006 IP
  3. x3sphere

    x3sphere Member

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #3

    ah, thanks - I noticed it wasn't echoing anything so I added

    $section = $_GET['section'];
    Code (markup):
    and now it works :D Cheers
     
    x3sphere, Oct 30, 2006 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's the beauty of dead simple debugging. ECHO the lot and see whether it is what you expected. Work your way up from there.
     
    T0PS3O, Oct 30, 2006 IP
  5. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #5

    I agree with you very much on this one TopS30 :)

    When I am debugging a script I start inserting echos and print_r's all the way along the script and see what the output is at the end. Very good and very useful then more advanced debugging techniques imo.
     
    drewbe121212, Oct 30, 2006 IP