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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:44:04+00:00 2026-06-03T15:44:04+00:00

I am using this query to get all the data but I also need

  • 0

I am using this query to get all the data but I also need add in it how many rows it’s returning.

Here is my code:

function getUsers($id){
    $users = $this->User->find('all', array('condition'=>array('my_id'=>$id)));
    $numUsers = sizeof($users);
    $users['User']['Total']= $numUsers;
    echo  json_encode($users);
}

The $dArray contains all the data for the users but I also want it to tell me how many users were there.

I was thinking that I would get data within the User object but this is what us gives me

Object
0: Object
1: Object
2: Object
3: Object
4: Object
5: Object
User: Object
Total: 6


instead of adding it to the 

0: Object
Company: Object
Group: Object
Team: Array[0]
User: Object
company_id: "20"
created: "2012-04-15 17:35:51"
email: "dd@gmail.com"
expiration_date: "2012-04-15 17:35:00"
firstname: "jason"
grants_id: null
group_id: "1"
id: "1"
lastname: "brawar"
modified: "2012-04-23 14:25:48"
name: null
password: "203e686b6a6938648ddd3eb0a8d95988ac638596"
phone: "abcd"
status: "Active"
type: null
username: "asim"
Total: 1
  • 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-03T15:44:06+00:00Added an answer on June 3, 2026 at 3:44 pm

    No need to do it in the query – just use PHP:

    <?php
    $this->User->recursive=-1;
    $users = $this->User->find('all', array('conditions'=>array('my_id'=>$id)));
    $numUsers = sizeof($users);
    

    This will give you the number of main items (ie Users), since any “extra” data you want to include via recursive or containable will be nested within each individual User array.

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

Sidebar

Related Questions

I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
The code we're using is straightforward in this part of the search query: myCriteria.Add(
I can't seem to get my query to stop using filesort. This is my
I have this query that inserts rows, using a subquery like so: INSERT INTO
I'm using System.Data.SQLite to query a database with c#/linq . The rows I want
I am using this query: SELECT DISTINCT pat.PublicationID FROM dbo.PubAdvTransData AS pat INNER JOIN
Currently, I am using this query, which does a pretty good job of finding
I am trying to return voice messages from a database using this query :
When using this SQL query: Select * from table_name what happens if the name
I'm using this SQL query to create an index: $query = CREATE INDEX id_index2

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.