Jump to content

PDO Object is NULL


Korferer

Recommended Posts

 
My code;

$sql = "SELECT SUM(IF(`submitdate` IS NULL , 1 , 0 )) as 'Survey Started But Not Completed' FROM `survey_$surveyid`";
$statement = $dbh->prepare($sql);
$statement->execute();
$result = $statement->fetch(PDO::FETCH_OBJ); //pass that data to an object

Is returning;
 

stdClass Object
(
    [Survey Started But Not Completed] => 
)


I need to set this to a vaule that I can actually print out on the screen... Like a "0" for example. At the moment it is just a NULL.
 
How do I do this??
 
These don't work;
 

$result  = 0;

$result = array(['Survey Started But Not Completed'] => "0");

 

Link to comment
https://forums.phpfreaks.com/topic/290206-pdo-object-is-null/
Share on other sites

Rather than SUM+IF, I'd use COUNT which will only count non-null values.

SELECT COUNT(`submitdate`) AS 'Survey Started But Not Completed' FROM `survey_$surveyid`

Side comment: tsk tsk for using multiple tables for multiple surveys. Should be just one table for everything.

Link to comment
https://forums.phpfreaks.com/topic/290206-pdo-object-is-null/#findComment-1486551
Share on other sites

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.