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 7407749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:46:47+00:00 2026-05-29T05:46:47+00:00

Having trouble with query results. The getSales() function works great the first time it

  • 0

Having trouble with query results. The getSales() function works great the first time it is called. When called again, the query produces no results. Here is a small chunk of code:

abstract class Reporting {
        protected function connect() {
            try {
                $this->dbh = PDOConnection::getInstance();

                if (!$this->dbh instanceof PDO) {
                    throw new CustomException('Unable to connect to database');
                }
            }
            catch (CustomException $e) {
                echo $e;
            }
        }
}
class TenMinuteSales extends Reporting {

        protected $date;

        public function __construct($date) {
            $this->date = new DateTime($date);
            $this->date = $this->date->format('Y-m-d');
        }

        public function beginReport() {
            parent::connect();
        }

        public function getSales($meridiem, $date) {
            try {
                $statement = "SELECT directory.location, IFNULL(sales.daily_sales,0.00) AS sales, IFNULL(sales.cover_counts,0) AS covers
                              FROM t_directory directory
                              LEFT JOIN v_sales_all sales
                              ON sales.site_id = directory.site_id
                              AND sales.business_date = :date
                              AND sales.meridiem = :meridiem
                              ORDER BY directory.site_id ASC
                              LIMIT :totalLocations";

                $sth = $this->dbh->prepare($statement);
                $sth->bindParam(':date', $date, PDO::PARAM_STR);
                $sth->bindParam(':meridiem', $meridiem, PDO::PARAM_STR);
                $sth->bindParam(':totalLocations', $this->totalLocations, PDO::PARAM_INT);
                $sth->execute();

                switch ($meridiem) {
                    case 'AM': 
                        $this->amSales = $sth->fetchAll(PDO::FETCH_ASSOC);
                        return $this->amSales;
                    case 'PM':
                        $this->pmSales = $sth->fetchAll(PDO::FETCH_ASSOC);
                        return $this->pmSales;
                }
            }
            catch (CustomException $e) {
                echo $e;
            }
        }

$tms = new TenMinuteSales($date);
$tms->beginReport();
$amSales = $tms->getSales('AM', $date);
$pmSales = $tms->getSales('PM', $date);

When I call getSales() for AM or PM sales numbers, the function successfully returns the data. When I call it a second time, the function doesn’t return any data. Not sure if I need to free the results or something along those lines. I tried unset($sth) and $sth->closeCursor(), none of which seems to fix my problem. Any help with fixing my issue would be greatly appreciated. Please let me know if more details are needed.

  • 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-05-29T05:46:48+00:00Added an answer on May 29, 2026 at 5:46 am

    As this is not the whole code, it is important to note that ->bindParam works by reference to a variable, which could result in unexpected behavior if you are not paying very close attention to everything that happens to those variables later on. If you don’t explicitly need a reference, using ->bindValue (which, as the name states, binds the variable by value) is safer, easier and most of all much clearer. Apparently this worked here, but exactly why is hard to state without complete code 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble writing a query. I have a support tabled called 'MYTABLE' and
I'm having trouble getting the results of a has_many query using php idiorm/paris. Following
I am having trouble and need some help finding a correct SQL query. Here
I am having trouble getting teh results i want from this mysql query. And
I am having trouble getting my query to return unique results. users_systems db setup:
I am having trouble pulling a query where i want to return results that
I am having trouble displaying results from a SQL query. I am trying to
I'm having trouble getting the correct results in my query. I'm using Mysql and
I'm having trouble getting the results I want from a Salesforce/Apex/SOQL query. I want:
I'm having trouble building a query. I can do what I want in 3

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.