Page 2 of 2

Posted: Mon Jul 23, 2007 2:43 pm
by superdezign

Code: Select all

print_r($dayResult[0]);
Put that directly before the if statement and see what you get.

Posted: Tue Jul 24, 2007 8:33 am
by bouncer
superdezign wrote:

Code: Select all

print_r($dayResult[0]);
Put that directly before the if statement and see what you get.
the output for this

Code: Select all

print_r($dayResult[0]);


was

Code: Select all

Array ( [id] => 14 [date] => 2007-07-30 [productID] => 13349 [cod] => 408081 [price] => 389 [description] => [auxiliar] => 0 [site] => 1 )
and for this

Code: Select all

print_r($dayResult);
was

Code: Select all

Array ( [0] => Array ( [id] => 14 [date] => 2007-07-30 [productID] => 13349 [cod] => 408081 [price] => 389 [description] => [auxiliar] => 0 [site] => 1 ) )
regards

Posted: Tue Jul 24, 2007 10:48 am
by superdezign
Works fine for me. Obviously, that line is not the problem. Is there anything else on that line? Before? After?

Posted: Tue Jul 24, 2007 10:52 am
by Begby
Are you posting the full code? Is there any chance that the 'if' statement is inside a function or anything?

Posted: Tue Jul 24, 2007 12:24 pm
by bouncer
this is the code in the main php file,

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'];
}
and this is returnProductDay function code,

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;
}
regards

Posted: Tue Jul 24, 2007 12:48 pm
by superdezign
Why the hell would you use settype? Have you ever heard of is_array() or isset()?

And I'm still not getting the same error as you. Is there anything else that you are failing to disclose regarding $dayResult?

Posted: Tue Jul 24, 2007 3:47 pm
by Begby
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?

Posted: Wed Jul 25, 2007 9:11 am
by bouncer
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?
yes, i'm getting notices.

by the way i'm using this statement,

Code: Select all

if ( is_array($dayResult) && ! empty($dayResult) ) {
        $productDay = $dayResult[0]['cod']; 
        $priceDay = $dayResult[0]['price']; 
}
and so far i'm not getting notices :) , do you think that this is a better solution ?

thanks in advance

Posted: Wed Jul 25, 2007 9:18 am
by superdezign
bouncer wrote:

Code: Select all

if ( is_array($dayResult) && ! empty($dayResult) ) {
        $productDay = $dayResult[0]['cod']; 
        $priceDay = $dayResult[0]['price']; 
}
and so far i'm not getting notices :) , do you think that this is a better solution ?
A better solution than settype()? By far. You may also want to check that each of those are set.

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; 
}
Always ensure that every variable that you use is valid before using it.

Posted: Wed Jul 25, 2007 10:42 am
by bouncer
thanks you all :D