Jump to content

Select COUNT(*) returns 0


ejaboneta

Recommended Posts

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'];

Link to comment
Share on other sites

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.

 

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.