...

View Full Version : key & value dissappears



turpentyne
08-12-2012, 09:26 PM
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?




$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>";
}

}

tangoforce
08-13-2012, 02:07 PM
In your foreach() loop you need to print_r() the value of $key and $value so that you can see whats really going on.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum