Jump to content

PDO Object is NULL


Korferer
Go to solution Solved by requinix,

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
Share on other sites

  • Solution

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.

Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.