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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:13:30+00:00 2026-06-06T17:13:30+00:00

Currently I’m running a MySQL query like this $query = SELECT t1.id AS ‘post_id’,

  • 0

Currently I’m running a MySQL query like this

$query = "
        SELECT 
        t1.id AS 'post_id',
        t1.post_title AS 'post_title',
        t1.post_status AS 'post_status',
        COUNT( t1.id ) AS 'row_count', //this one is not working
        COUNT( t2.tag_id ) AS 'link_count',
        GROUP_CONCAT( t2.tag_id) AS 'link_id',
        GROUP_CONCAT( t2.url) AS 'url',
        GROUP_CONCAT( t2.title) AS 'title',
        GROUP_CONCAT( t2.active) AS 'active',
        FROM $posts_table AS t1
        JOIN $tags_table AS t2 ON ( t1.id = t2.post_id )
        GROUP BY t1.id
        ORDER BY t1.id DESC
        LIMIT $start_from, $row_to_show;
    ";

Every part of this query is executing well except COUNT( t1.id ) AS 'row_count', line.

I want to count total numbers of rows found in t1 table but when I’m dumping the array

$result = $wpdb->get_results($query);
var_dump($result->row_count);

It is giving me NULL.

If I use it inside a loop

foreach ( $result as $result ){
    echo $result->row_count;
}

Then the value is same as link_count that is declared in the very next line COUNT( t2.link_id ) AS 'link_count', gives the value I want.

Please give me some idea about how I can use pagination (like 10 out of 30 results) on this query.

  • 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-06T17:13:31+00:00Added an answer on June 6, 2026 at 5:13 pm

    I tried many but didn’t succeed so I made another separate DB query for just pagination.

    $page_query = "
        SELECT p.id 
        FROM 
        $posts_table as p, 
        $tag_table as c
        WHERE p.id=c.post_id
        GROUP BY p.id
    ";
    

    it gives me the result of total numbers of rows that I can use for pagination.

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

Sidebar

Related Questions

Currently, I have a log file of messages in one table in a MySQL
Currently, my ListViews look like this: How can I achieve that Windows 7 native
Currently, I'm storing MySQL query results in an array of objects, where each object
Currently I'm starting a new Activity and calling finish on a current one. Is
Currently I have this code: <?php echo '<meta name=robots content=noindex>'; $arr = json_decode(file_get_contents(http://media1.clubpenguin.com/play/en/web_service/game_configs/ paper_items.json),true);
Currently I am debugging the signing of an Android app. And this would be
Currently I am adding object by creating it like: type TRecord = class private
Currently my query is very heavy, the table (table A) I need to update
Currently, most of the popular websites, like google, yahoo detect if the user connection
Currently I have a web service running in a tomcat (http:// localhost:8080/myApp/getUsers ). My

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.