# How to get database data in cakephp

**URL:** <https://discourse.cakephp.org/t/how-to-get-database-data-in-cakephp/6509>\
**Category:** Uncategorized\
**Created:** [August 19, 2019, 10:47am UTC](https://discourse.cakephp.org/t/how-to-get-database-data-in-cakephp/6509 "2019-08-19T10:47:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshad](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@harshad](https://discourse.cakephp.org/u/harshad)\
**Post date:** [August 19, 2019, 10:47am UTC](https://discourse.cakephp.org/t/how-to-get-database-data-in-cakephp/6509/1 "2019-08-19T10:47:50Z")

</div>

how to get specific data in database using specific id and show index.ctp using Cakephp

---

<div class="post-metadata">

**Author:** ![FinlayDaG33k](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/finlaydag33k/32/1049_2.png) [@FinlayDaG33k](https://discourse.cakephp.org/u/FinlayDaG33k)\
**Post date:** [August 19, 2019, 11:21am UTC](https://discourse.cakephp.org/t/how-to-get-database-data-in-cakephp/6509/2 "2019-08-19T11:21:07Z")

</div>

Have you even finished the tutorial?  
Get the data from the controller using the ORM and pass the result to the view.

---

<div class="post-metadata">

**Author:** ![harshad](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@harshad](https://discourse.cakephp.org/u/harshad)\
**Post date:** [August 19, 2019, 11:55am UTC](https://discourse.cakephp.org/t/how-to-get-database-data-in-cakephp/6509/3 "2019-08-19T11:55:14Z")

</div>

yes i did but specific user login then who logged in it only get user data I want  
it is my problem.  
so how do i  
public function index()  
{  
$idd=$this-\>Auth-\>user(‘id’);  
echo $idd;  
**$users = $this-\>paginate($this-\>Users); //this show all data**  
$this-\>set(compact(‘users’));  
}  
but i want only suppose idd=1 then only show who id 1 get record only show.

how to solve?

---

<div class="post-metadata">

**Author:** ![FinlayDaG33k](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/finlaydag33k/32/1049_2.png) [@FinlayDaG33k](https://discourse.cakephp.org/u/FinlayDaG33k)\
**Post date:** [August 19, 2019, 2:13pm UTC](https://discourse.cakephp.org/t/how-to-get-database-data-in-cakephp/6509/4 "2019-08-19T14:13:29Z")

</div>

Why are you trying to paginate users if you’re only getting one user anyways?  
Just do this and you’re pretty much done:

```php
$this->set('user', $this->Auth->user());

```

---

<div class="post-metadata">

**Author:** ![harshad](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@harshad](https://discourse.cakephp.org/u/harshad)\
**Post date:** [August 19, 2019, 4:07pm UTC](https://discourse.cakephp.org/t/how-to-get-database-data-in-cakephp/6509/5 "2019-08-19T16:07:07Z")

</div>

Thanks.  
I did below tricks,  
$id=$this-\>Auth-\>user(‘id’);  
$query = $this-\>Users-\>findById($id);  
$this-\>set(compact(‘query’));  
that’s it …  
it works.  
Thank you for ,  
“$this-\>set(‘user’, $this-\>Auth-\>user());”  
that’s I remember.  
Thank you for support.
