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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:36:09+00:00 2026-06-14T15:36:09+00:00

What am I doing wrong here? I’m simply retrieving results from a table and

  • 0

What am I doing wrong here? I’m simply retrieving results from a table and then adding them to an array. Everything works as expected until I check for an empty result…

This gets the match, adds it to my array and echoes the result as expected:

$today = date('Y-m-d', strtotime('now'));

$sth = $db->prepare("SELECT id_email FROM db WHERE hardcopy = '1' AND hardcopy_date <= :today AND hardcopy_sent = '0' ORDER BY id_email ASC");

$sth->bindParam(':today', $today, PDO::PARAM_STR);

if(!$sth->execute()) {
    $db = null;
    exit();
}

while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
    $this->id_email[] = $row['id_email'];
    echo $row['id_email'];
}

$db = null;
return true;

When I try to check for an empty result, my code returns ’empty’, but no longer yields the matching result:

$today = date('Y-m-d', strtotime('now'));

$sth = $db->prepare("SELECT id_email FROM db WHERE hardcopy = '1' AND hardcopy_date <= :today AND hardcopy_sent = '0' ORDER BY id_email ASC");

$sth->bindParam(':today',$today, PDO::PARAM_STR);

if(!$sth->execute()) {
    $db = null;
    exit();
}

if ($sth->fetchColumn()) {
    echo 'not empty';
    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
        $this->id_email[] = $row['id_email'];
        echo $row['id_email'];
    }
    $db = null;
    return true;
}
echo 'empty';
$db = null;
return false;
  • 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-14T15:36:10+00:00Added an answer on June 14, 2026 at 3:36 pm

    You’re throwing away a result row when you do $sth->fetchColumn(). That’s not how you check if there are any results. You do

    if ($sth->rowCount() > 0) {
      ... got results ...
    } else {
       echo 'nothing';
    }
    

    Relevant documentation is here: PDOStatement::rowCount

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

Sidebar

Related Questions

What am I doing wrong here? $sub_data = $this->Subscriber->find('all', array( 'joins' => array( 'table'
What am I doing wrong here? private void SendMail(string from, string body) { string
What am I doing wrong here? If FilePath.ToLower().Contains(.pdf) Then Dim Replaced As String =
What am I doing wrong here? I am trying to extract from this list
What am I doing wrong here? I am wanting to display integers from 1-100
What am I doing wrong here. I want the array we get at first
What am I doing wrong here with passing a char array to a function
What am I doing wrong here: <?php if (isset($_POST['submitted'])) { $errors = array(); require_once
What am I doing wrong here folks? <?php include 'header.php'; /** * Display a
What am I doing wrong here? I'm trying to get started with jQuery UI

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.