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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:43:34+00:00 2026-06-05T16:43:34+00:00

The following is a code snippet of my application. Bear in mind that I

  • 0

The following is a code snippet of my application. Bear in mind that I am very, very new to PDO (as in, started figuring it out today) so I’m a bit confused.

Now, the if statement returns 1, as it should. This is expected. However, what’s unexpected happens after I set $node: after setting it, it appears to be FALSE. What? Just a few lines before, my fetch() attempt returned the expected value, so I have no idea what’s happening.

$sth = $dbh->prepare("
    SELECT *, COUNT(*) AS num_rows
    FROM flow
    INNER JOIN flow_strings
        USING(node_id)
    WHERE
        (
            parent = 0
            OR parent = :user_flow
        )
        AND source = 0
        AND string = :input
    ");
$sth->bindParam(':user_flow', $user->info->flow);
$sth->bindParam(':input', $input_sentence);
$sth->execute();

// If node exists.
if ($sth->fetch()->num_rows > 0)
{
    // Get the information for the node.
    $node = $sth->fetch();

[...] etc

I am guessing that the cursor is moved ahead, and then there’s nothing left to read, so FALSE is returned. Surely there’s a way to work around this, though! When I run $sth->fetch()->num_rows, I’m not trying to change anyything–I’m just trying to read a value. Is there a workaround? Am I doing something weird? I’m so lost, haha.

Thanks! 🙂


EDIT:

Notice: Undefined variable: node_count ... on line 56

// Retrieve all child nodes under $parent.
$node_query = $dbh->prepare("
    SELECT *, COUNT(*) AS num_rows
    FROM flow
    WHERE parent = :parent
    ");
$node_query->bindParam(':parent', $parent);
$node_query->execute();

// If child nodes exist.
if ($node_count = $node_query->fetch() && $node_count->num_rows > 0) // Line 56
{

[...] etc
  • 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-05T16:43:36+00:00Added an answer on June 5, 2026 at 4:43 pm

    Assign the data array to some variable and use it without further fetches:

    if (($row = $sth->fetch()) && $row->num_rows > 0) {
        // work with $row here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently making a SMS Application in Android, the following is a code snippet
I am having the following code snippet in my application screen to show a
I have the following code snippet. SqlCommand cmd = new SqlCommand(SELECT FName,LName FROM EMPLOYEE_TABLE
I've got the following code snippet that I'm thinking of refactoring to a more
I have the following code snippet that builds chained select boxes based on data
I have following code snippet in my application activity. If user is landing on
Following simplified code snippet: #include <QtGui> int main(int argc, char **argv) { QApplication app(argc,
The following code snippet on SQL server 2005 fails on the ampersand '&': select
The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk
The following code snippet attempts to create a Tib DaemonManager connecting to a particular

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.