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"); Quote Link to comment https://forums.phpfreaks.com/topic/290206-pdo-object-is-null/ Share on other sites More sharing options...
Solution requinix Posted July 31, 2014 Solution Share Posted July 31, 2014 (edited) 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 July 31, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/290206-pdo-object-is-null/#findComment-1486551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.