simpson_121919 Posted January 5, 2014 Share Posted January 5, 2014 I am trying to use a SELECT count(*) to check if a given record exists but its not working and always returns FALSE. I am stumped. At the very least I would think it would return 0. I have checked the SELECT statement in myphpAdmn to make sure that was not the issue. Here is my code - $Qchoice = "SELECT count(*) FROM collect_temp_table WHERE user_ID=:userID AND gID=:gID AND rID=:rid"; $QchoicePreped = $dbh->prepare($Qchoice); $QchoicePreped->bindParam(':userID',$userID,PDO::PARAM_STR,75); $QchoicePreped->bindParam(':gID',$gID,PDO::PARAM_STR,; $QchoicePreped->bindParam(':rID',$rID,PDO::PARAM_STR,3); $QchoicePreped->execute(); $QchoiceResult = $QchoicePreped->fetch(PDO::FETCH_NUM); Any help would be appreciated, thanks. Link to comment https://forums.phpfreaks.com/topic/285110-how-to-do-a-select-count/ Share on other sites More sharing options...
mac_gyver Posted January 5, 2014 Share Posted January 5, 2014 $QchoiceResult is an array. if you are not referencing $QchoiceResult[0], you won't get the selected count(*) value from the query. edit: you also have a spelling/capitalization error between the :rid placeholder in the query and the bind statement that is either throwing a php warning or an exception, depending on what pdo error mode you are using. you always need to test for errors before you can use the result from any step in your code. Link to comment https://forums.phpfreaks.com/topic/285110-how-to-do-a-select-count/#findComment-1463936 Share on other sites More sharing options...
simpson_121919 Posted January 5, 2014 Author Share Posted January 5, 2014 That was it, I looked at that code for awhile and did not see that. I think I have been at this too long and need to give my eyes a rest. Thank you for the advice and help. Link to comment https://forums.phpfreaks.com/topic/285110-how-to-do-a-select-count/#findComment-1463950 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.