[eluser]Fielder[/eluser]
I'm having a problem getting this isset command to locate a particular value in my array. It keeps going into the IF statement. Am I missing something?
I'm getting "Undefined index: 2975" error, when I know for a fact 2975 exists in the storeArray $key and $row['store_id']. I've var_dump both $storeArray and $stores and they both show 2975.
Any ideas? Let me know if more info. is needed.
Code: foreach ($c as $key => $val)
{
.
.
.
$storeArray[$key] = array(
'storename' => $store[0]['storename_name'],
'storenum' => $store[0]['store_number'],
'newAd_count' => $newAd_count,
'renewAd_count' => $val - $newAd_count,
'totAd_count' => $val,
'spaces_count' => $spaces_count,
'print' => $print,
'lastqtrAd_count' => $lastqtrAd,
'cancelled' => $val - $cancelled,
'freeAd_count' => $freeAd,
'revenue' => '$ '.number_format($rev, 2)
);
}
$stores = $this->store->getStorebyZone($data['zone']);
foreach ($stores as $row)
{
if (!isset($storeArray[$row['store_id']]))
{
$storeArray[$row['store_id']] = array(
'storename' => $row['storename_name'],
'storenum' => $row['store_number'],
'newAd_count' => '0',
'renewAd_count' => '0',
'totAd_count' => '0',
'spaces_count' => '0',
'print' => 'N',
'lastqtrAd_count' => '0',
'cancelled' => '0',
'freeAd_count' => '0',
'revenue' => '$ '.number_format(0, 2)
);
}
}
var_dump for $storeArray
Code: array(8) { [2975]=> array(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> int(4) ["renewAd_count"]=> int(4) ["totAd_count"]=> int(8) ["spaces_count"]=> int(10) ["print"]=> string(1) "Y" ["lastqtrAd_count"]=> int(9) ["cancelled"]=> int(1) ["freeAd_count"]=> int(4) ["revenue"]=> string(
var_dump for $stores
Code: [287]=> array(14) { ["store_id"]=> string(4) "2975" ["storename_name"]=> string(9) "Appletree" ["store_number"]=> string(3) "736" ["store_address"]=> string(11) "2000 Hwy 21" ["store_city"]=> string(5) "Bryan" ["store_state"]=> string(2) "TX" ["store_zip"]=> string(5) "77803" ["store_cycle"]=> string(1) "B" ["store_phone"]=> string(14) "(979) 778-0134" ["store_notes"]=> string(0) "" ["store_open"]=> string(1) "1" ["store_alive"]=> string(1) "1" ["store_upscode"]=> string(11) "APT001-0736" ["zone_number"]=> string(1) "1" }
[eluser]skunkbad[/eluser]
What happens if you var_dump($storeArray[$row['store_id']]) right before the if statement ??
[eluser]Fielder[/eluser]
NULL
[eluser]Fielder[/eluser]
I think it has something to do with the datatype of the keys.
Within my code, I'm merging a 2nd array($subTotal) with my primary $storeArray.
$storeArray keys are all numeric, ie 2975. However, the keys on $subTotal are alpha, ie Appletree.
So now my $storeArray has mixed key datatypes between numeric and alpha. Could that be causing a problem with my isset?
Code: $subTotal = $this->rtui_app->subTotal($storeArray);
$storeArray = array_merge($storeArray, $subTotal);
[eluser]mah0001[/eluser]
On which line you are getting the Undefined index error?
[eluser]Fielder[/eluser]
I'm sorry, let me clarify. It always goes into the IF statement as per my code in the original post because of the !, and does not throw an error.
I only get the Undefined index error when I throw in var_dump($storeArray[$row['store_id']]) anywhere.
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined index: 2975
Filename: controllers/all_search.php
Line Number: 403 <-- line with var_dump
NULL
[eluser]Fielder[/eluser]
I get these also
'Appletree' key comes from the merged array with $storeArray.
Code: var_dump($storeArray['Appletree']);
Quote:array(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(5) "Total" ["newAd_count"]=> int(2) ["renewAd_count"]=> int(7) ["totAd_count"]=> int(9) ["spaces_count"]=> int(10) ["print"]=> int(0) ["lastqtrAd_count"]=> int(8) ["cancelled"]=> int(1) ["freeAd_count"]=> int(2) ["revenue"]=> string(8) "$ 345.04" }
and this actually gives me Undefined Offset on the var_dump, but still spits out the dump below.
Code: var_dump($storeArray[2975]);
Quote:array(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> string(1) "0" ["renewAd_count"]=> string(1) "0" ["totAd_count"]=> string(1) "0" ["spaces_count"]=> string(1) "0" ["print"]=> string(1) "N" ["lastqtrAd_count"]=> string(1) "0" ["cancelled"]=> string(1) "0" ["freeAd_count"]=> string(1) "0" ["revenue"]=> string(6) "$ 0.00" }
and this gives me Undefined index on the var_dump as previously mentioned. Still spits out the dump below.
Code: var_dump($storeArray['2975']);
Quote:array(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> string(1) "0" ["renewAd_count"]=> string(1) "0" ["totAd_count"]=> string(1) "0" ["spaces_count"]=> string(1) "0" ["print"]=> string(1) "N" ["lastqtrAd_count"]=> string(1) "0" ["cancelled"]=> string(1) "0" ["freeAd_count"]=> string(1) "0" ["revenue"]=> string(6) "$ 0.00" }
[eluser]mah0001[/eluser]
replace your var_dump($storeArray[2975]) with the code below, and re-post the output.
Code: echo 'start';
var_dump($storeArray[2975]);
echo 'end';
If you get a Undefined index or Offset notice, you should not be getting any other output from the var_dump.
[eluser]Fielder[/eluser]
Code: echo 'start';
var_dump($storeArray[2975]);
echo 'end';
foreach ($stores as $row)
{
if (!isset($storeArray[$row['store_id']]))
{
$storeArray[$row['store_id']] = array(
//'storeid' => $row['store_id'],
'storename' => $row['storename_name'],
'storenum' => $row['store_number'],
'newAd_count' => '0',
'renewAd_count' => '0',
'totAd_count' => '0',
'spaces_count' => '0',
'print' => 'N',
'lastqtrAd_count' => '0',
'cancelled' => '0',
'freeAd_count' => '0',
'revenue' => '$ '.number_format(0, 2)
);
}
}
output with no var_dump results.
Quote:start
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2975
Filename: controllers/all_search.php
Line Number: 400
NULL end
When I move the var_dump inside the foreach...
Code: foreach ($stores as $row)
{
echo 'start';
var_dump($storeArray[2975]);
echo 'end';
if (!isset($storeArray[$row['store_id']]))
{
$storeArray[$row['store_id']] = array(
//'storeid' => $row['store_id'],
'storename' => $row['storename_name'],
'storenum' => $row['store_number'],
'newAd_count' => '0',
'renewAd_count' => '0',
'totAd_count' => '0',
'spaces_count' => '0',
'print' => 'N',
'lastqtrAd_count' => '0',
'cancelled' => '0',
'freeAd_count' => '0',
'revenue' => '$ '.number_format(0, 2)
);
}
}
Output. Note that the foreach loops through all $stores instances. It seems when it reaches 2975 it starts output the var_dump.
Quote:.
<repetative PHP Error shows for each loop>
.
.
start
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2975
Filename: controllers/all_search.php
Line Number: 412
NULL endstart
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2975
Filename: controllers/all_search.php
Line Number: 412
NULL endstartarray(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> string(1) "0" ["renewAd_count"]=> string(1) "0" ["totAd_count"]=> string(1) "0" ["spaces_count"]=> string(1) "0" ["print"]=> string(1) "N" ["lastqtrAd_count"]=> string(1) "0" ["cancelled"]=> string(1) "0" ["freeAd_count"]=> string(1) "0" ["revenue"]=> string(6) "$ 0.00" } endstartarray(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> string(1) "0" ["renewAd_count"]=> string(1) "0" ["totAd_count"]=> string(1) "0" ["spaces_count"]=> string(1) "0" ["print"]=> string(1) "N" ["lastqtrAd_count"]=> string(1) "0" ["cancelled"]=> string(1) "0" ["freeAd_count"]=> string(1) "0" ["revenue"]=> string(6) "$ 0.00" } endstartarray(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> string(1) "0" ["renewAd_count"]=> string(1) "0" ["totAd_count"]=> string(1) "0" ["spaces_count"]=> string(1) "0" ["print"]=> string(1) "N" ["lastqtrAd_count"]=> string(1) "0" ["cancelled"]=> string(1) "0" ["freeAd_count"]=> string(1) "0" ["revenue"]=> string(6) "$ 0.00" } endstartarray(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> string(1) "0" ["renewAd_count"]=> string(1) "0" ["totAd_count"]=> string(1) "0" ["spaces_count"]=> string(1) "0" ["print"]=> string(1) "N" ["lastqtrAd_count"]=> string(1) "0" ["cancelled"]=> string(1) "0" ["freeAd_count"]=> string(1) "0" ["revenue"]=> string(6) "$ 0.00" } end
[eluser]mah0001[/eluser]
It looks like the key 2975 exists, Change your code to:
Code: foreach ($stores as $row)
{
if (!isset($storeArray[$row['store_id']]))
{
$storeArray[$row['store_id']] = array(
//'storeid' => $row['store_id'],
'storename' => $row['storename_name'],
'storenum' => $row['store_number'],
'newAd_count' => '0',
'renewAd_count' => '0',
'totAd_count' => '0',
'spaces_count' => '0',
'print' => 'N',
'lastqtrAd_count' => '0',
'cancelled' => '0',
'freeAd_count' => '0',
'revenue' => '$ '.number_format(0, 2)
);
}
}
echo 'start';
var_dump($storeArray[2975]);
echo 'end';
You should see the values for the 2975 key printed instead of NULL. I think your problem is starting after you merge your array:
Code: $subTotal = $this->rtui_app->subTotal($storeArray);
$storeArray = array_merge($storeArray, $subTotal);
Add the var_dump after the merge and post the part where you see your key 2975.
Code: $subTotal = $this->rtui_app->subTotal($storeArray);
$storeArray = array_merge($storeArray, $subTotal);
echo '<pre>';
var_dump($storeArray);
echo '</pre>';
//also try
echo '<pre>';
var_dump($storeArray[2975]);
echo '</pre>';
|