Jump to content

Script fails if value inside an array doesnt exist


UrbanDweller

Recommended Posts

Hey,

I have this code below which seems to completely fail sending my laptop cpu fan on a frenzy. All I am wanting to do is find whether the id in the url is located inside the array below else state its not in an error saying its not a valid id (for people who change the url shown below). At the moment it doesnt like the else statement if the isset clause it not true. (I have also tried, array_key_exists)

 

All I can think is that it get stuck looking for an id that doesnt exist inside the array but keeps searching though I dont know much about arrays etc. Besides this when a id is inside the array the script works like I want it to.

Any ideas would be much appreciated as this is hold me back at the moment :(

 

//url: http://localhost/website/shop.php?id=10197

// Array is built from table prior to this as it will grow in size
$_SESSION['storesProducts'] = Array ( [10197] => 0 [10198] => 0 [10199] => 1 [10200] => 1 [10201] => 1 [10202] => 1 [10205] => 0 [10206] => 1 [10207] => 1 )

if(isset($_SESSION['storesProducts'][$id])){
$storesProducts = $_SESSION['storesProducts'][$id];
if($storesProducts == 0){
	$list = $this->displayCategories($id);
}else{
	$createProducts = new constructProducts();
	$products = $createProducts->pagination($id);
}
}else{
$list = "ITS NOT HERE";
}
$output = new outputShop();
$output->display($list, $products);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.