Posted: Mon Jul 23, 2007 2:43 pm
Code: Select all
print_r($dayResult[0]);A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
print_r($dayResult[0]);the output for thissuperdezign wrote:Put that directly before the if statement and see what you get.Code: Select all
print_r($dayResult[0]);
Code: Select all
print_r($dayResult[0]);Code: Select all
Array ( [id] => 14 [date] => 2007-07-30 [productID] => 13349 [cod] => 408081 [price] => 389 [description] => [auxiliar] => 0 [site] => 1 )Code: Select all
print_r($dayResult);Code: Select all
Array ( [0] => Array ( [id] => 14 [date] => 2007-07-30 [productID] => 13349 [cod] => 408081 [price] => 389 [description] => [auxiliar] => 0 [site] => 1 ) )Code: Select all
$today = date("Y-m-d");
$dayResult = $dbproductDay->returnProductDay($today,$codProd,$_site);
settype($dayResult,"array"); // --> if i dont use this i'll get Fatal error in the if statement
if($dayResult[0]['productID'] != ""){
$productDay = $dayResult[0]['cod'];
$priceDay = $dayResult[0]['price'];
}Code: Select all
function returnProductDay($today,$codProd,$_site) {
$query = "SELECT * FROM productsDay WHERE date = '$date' AND cod = '$codProd' AND site = '$_site'";
$result = $this->cDb->openCursor($query);
return $result;
}yes, i'm getting notices.Begby wrote:It appears that $result is getting returned as null or an empty string ''.
Are you absolutely 100% positive that you did those print_r()'s and var_dumps()'s with the exact same data/context that was giving you the notice?
Also, I thought you were getting Notices, not fatal errors?
Code: Select all
if ( is_array($dayResult) && ! empty($dayResult) ) {
$productDay = $dayResult[0]['cod'];
$priceDay = $dayResult[0]['price'];
}A better solution than settype()? By far. You may also want to check that each of those are set.bouncer wrote:and so far i'm not getting noticesCode: Select all
if ( is_array($dayResult) && ! empty($dayResult) ) { $productDay = $dayResult[0]['cod']; $priceDay = $dayResult[0]['price']; }, do you think that this is a better solution ?
Code: Select all
if ( is_array($dayResult) && ! empty($dayResult) && isset($dayResult[0]) ) {
$productDay = isset($dayResult[0]['cod']) ? $dayResult[0]['cod'] : NULL;
$priceDay = isset($dayResult[0]['price']) ? $dayResult[0]['price'] : NULL;
}