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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:34:08+00:00 2026-06-02T21:34:08+00:00

I’ve checked this in phpMyAdmin, and it returned 1 result: SELECT id, name FROM

  • 0

I’ve checked this in phpMyAdmin, and it returned 1 result:

    SELECT id, name
      FROM tbl_product_category
INNER JOIN tbl_product_cat_basket AS basket
        ON id = basket.cat_id
     WHERE basket.product_id = 2
     LIMIT 0,1

I then checked this in phpMyAdmin, and it returned COUNT = 1:

    SELECT COUNT(*)
      FROM tbl_product_category
INNER JOIN tbl_product_cat_basket AS basket
        ON id = basket.cat_id
     WHERE basket.product_id = 2
     LIMIT 0,1

Now I don’t understand why this causes $rows to return empty string or null:

function getProductCategory($product_id) {
    $sql = "SELECT id, name FROM tbl_product_category
        INNER JOIN tbl_product_cat_basket AS basket
                ON id = basket.cat_id
             WHERE basket.product_id = ?
             LIMIT 0,1;";
    $data = array((int)$product_id);
    $rows = dbRowsCount($sql, $data);
logErrors("getProductCategory(".$product_id.") returned rows: ".$rows);
    if ($rows == 1) {
        dbQuery($sql, $data);
        return dbFetch();
    } else {
        return null;
    }
}

The logErrors method gives me this output:

getProductCategory(1) returned rows:
getProductCategory(2) returned rows:
getProductCategory(3) returned rows:
getProductCategory(4) returned rows:
getProductCategory(5) returned rows:

and so I’m returning null from the method.

My dbRowsCount(...) method converts the SQL to do a SELECT COUNT(*), then dbQuery(...) executes the real query. This is strange because the dbRowsCount(...) so far has always returned the correct rows for my other queries.

Here it is anyway:

function dbRowsCount($sql, $data) {
    global $db, $query;
    $regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
    if (preg_match($regex, $sql, $output) > 0) {
        $query = $db->prepare("SELECT COUNT(*) FROM {$output[1]}");
        $query->setFetchMode(PDO::FETCH_NUM);
        if ($data != null)
            $query->execute($data);
        else
            $query->execute();
        if (!$query) {
            echo "Oops! There was an error: PDOStatement returned false.";
            exit;
        }
        return $query->fetchColumn();
    }
    return false;
}

So what’s gone wrong?


Edit

Here is some output from my program:
[Original Query]
[Query after regex]

SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(1) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(2) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(3) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(4) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(5) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(6) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(7) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(8) returned rows: 7
SELECT id, name FROM tbl_product_category INNER JOIN tbl_product_cat_basket AS basket ON id = basket.cat_id WHERE basket.product_id = ? LIMIT 0,1;
SELECT COUNT(*) FROM tbl_product_category

getProductCategory(9) returned rows: 7
SELECT * FROM tbl_store_admin WHERE php_sesskey=?;
SELECT COUNT(*) FROM tbl_store_admin WHERE php_sesskey=?;

SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;

SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;

SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;

SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;

SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;

SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;

SELECT * FROM tbl_menu_cat_basket WHERE menu_id=?;
SELECT COUNT(*) FROM tbl_menu_cat_basket WHERE menu_id=?;

SELECT * FROM tbl_product ORDER BY last_update ASC;
SELECT COUNT(*) FROM tbl_product ORDER BY last_update ASC;
  • 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-02T21:34:11+00:00Added an answer on June 2, 2026 at 9:34 pm

    Your RegeExp doesn’t match, it’s missing the dot-all flag (/is in total).

    This causes . to also match newlines in your string.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.