Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    key & value dissappears

    Trying to plod my way through this one, and I'm stumped yet again.

    The key is not passing, neither is the key's value. If I put in hard values, it works, but not with the key. That, and is there a way to put the query outside and do it just once, instead of with each loop?

    PHP Code:

    $results_done 
    $_SESSION['options_picked'];

    print_r($results_done);

    echo 
    "<div style='background-color:#000;width:170px;padding:15px; margin:10px;float:left;posiiton:absolute;Top:-100px; right:10px;'><font color='#ffffff'> <h3>You've chosen</h3>";
       
    print_r($results_done);

    // this will equal something like Array ( [0] => [1] => 34 [2] => 1 ) 
    // but it isn't working.

    foreach($results_done as $key => $val) {
        
        switch(
    $key) {
         case 
    0:
            
    $q_cat 4;
            break; 
            
        case 
    1:
            
    $q_cat 4;
            break; 
        case 
    2:
            
    $q_cat 1;
            break;
        case 
    3:
            
    $q_cat 11;
            break;
        case 
    4:
            
    $q_cat 2;
            break;
        case 
    5:
            
    $q_cat 10;
            break;
        case 
    6:
            
    $q_cat 9;
            break;
        default: 
    // If the key is not 1-6
            
    $q_cat = -1;


        }
        
        
    $query_cats mysql_query("SELECT tbl_component_categories.ID, tbl_component_categories.folder_path, tbl_component_categories.comp_cat_name, tbl_components.component_name FROM tbl_components JOIN tbl_component_categories on $q_cat = tbl_component_categories.ID
    where tbl_components.ID = $val"
    );

        if (!
    $query_cats) {
            
    $message  'Invalid query: ' mysql_error() . "\n";
            
    $message .= 'Whole query: ' $query_cats;
            die(
    $message);
        }


         while (
    $row mysql_fetch_array($query_cats)) { 
     
         echo 
    $row['comp_cat_name'].": ".$row['component_name']."<br>";
         }
     


  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    In your foreach() loop you need to print_r() the value of $key and $value so that you can see whats really going on.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •