Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8448955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:33:57+00:00 2026-06-10T10:33:57+00:00

I am almost certain my query is being cached. It is a SELECT statement.

  • 0

I am almost certain my query is being cached. It is a SELECT statement.

Here is an example situation. There are currently 2 pending orders. I have a script that displays a notification of pending orders on the home page to notify the warehouse if any new orders have been placed. I placed an order to test out if the “2” would update to “3” and it didn’t. I think my query is being cached, because when I run the query from phpMyAdmin it shows “3” but when ran through PHP it only shows “2”. Any ideas how to fix this or disable caching on specific queries?

Here was my original code

<?php
if( protectThis("1, 2") ) :
$pending = $conn->query("SELECT count(*) FROM orders WHERE `status` =0");
$pending2 = $pending->fetch();
$pendingcount = count($pending2);
if ($pendingcount > 0) {
?>
<div class="orange warning">
    <p>
        <strong>Pending Order Notification</strong>
        <br />There are currently <strong><?php echo $pendingcount; ?></strong> pending orders.
        <br /><a style="color:white;margin-top:10px;" class="btn btn-inverse" href="orders_pending.php"><i>Click here to view them.</i></a>
    </p>
    <div class="shadow-out"></div>
</div>
<?php
}
endif;

I tried altering the query after reading up on trying to disable the caching for specific queries and tried the following

SELECT SQL_NO_CACHE count(*) FROM orders WHERE `status` =0

Apparently that didn’t work either.

I’m not sure what to do. :\

Any help is much appreciated.


“EDIT 1”

$pending = $conn->query("SELECT count(*) FROM orders WHERE `status` =0");
// $pending2 = $pending->fetch();
// $pendingcount = count($pending2);
$pendingcount = $pending->rowCount();
if ($pendingcount > 0) {
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:33:59+00:00Added an answer on June 10, 2026 at 10:33 am

    I think you are counting the wrong way. Try var_dump($pending2). I guess you’ll get this output:

    array(2) {
      [0]=>
      int(3)
      ["COUNT(*)"]=>
      int(3)
    }
    

    $pending2 is an array containing the only row your query returned, with the only column indexed by both column name and 0-indexed column number. Any single-row resultset will look like this, and if you count it, it will always output 2.

    So instead of this:

    $pendingcount = count($pending2);
    

    you should use this:

    $pendingcount = $pending2[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When invoking the 'java' process, I'm almost certain there is a way to have
Currently I'm having a solution, but I'm almost certain that there's a better solution
I'm almost certain about the answer, but the situation is so critical that I
I'm almost certain I know the answer to this question, but I'm hoping there's
Cannot get this statement to update the table and am almost certain my problem
Almost anywhere I read about programming with CUDA there is a mention of the
Almost any mature program that involves text implements double click to select the word
I'm not used to doing things the python way yet, but I'm almost certain
I have compiled OpenCV with QT. I'm now facing an error which I'm almost
I currently have an asp.net page, that takes in the data from this view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.