ejaboneta Posted November 16, 2010 Share Posted November 16, 2010 I have a view with a column named 'agent'. My queries are supposed to count all the rows for each agent. However, about an hour ago, several agents counts suddenly come up as 0. Only a couple come up as 0, the rest are accurate. All the counts have been accurate for weeks and I haven't changed anything. I echoed the sql from my php and ran the queries directly on the database and they come up right. It's just from the site where a couple of them are coming up 0. I've check my code and can't figure it out. Anyone know why this would happen or where i can look to figure it out? $sql = "SELECT count(*) AS count1 FROM dbo.PolicyStatuses WHERE agent LIKE '$agent' "; $query = mssql_query($sql); $fetch = mssql_fetch_assoc($query); echo $fetch['count1']; Quote Link to comment https://forums.phpfreaks.com/topic/218879-select-count-returns-0/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2010 Share Posted November 16, 2010 Is there anything interesting ABOUT what the actual values are that would help pin down if this might be a bug or a limitation with the database driver or with php? Are all the actual values (that come out as zero using php code) all greater than some value, while all the values that work are all less then some value? Is the code that you posted all the code that duplicates the problem, in case you have some code that contains a logic error or is doing some math on the value that chokes under some conditions? Any chance that your page is being requested twice by browsers and the second time the $agent is empty and you see the zero result of that? I would recommend logging the actual query every time the page gets requested so that you can see a record of every query that gets executed. See the error_log function to log the $sql variable to a file. Quote Link to comment https://forums.phpfreaks.com/topic/218879-select-count-returns-0/#findComment-1135158 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.