Korferer Posted July 31, 2014 Share Posted July 31, 2014 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 More sharing options...
requinix Posted July 31, 2014 Share Posted July 31, 2014 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.