# Database Performance

**URL:** <https://forum.kirupa.com/t/database-performance/34101>\
**Category:** programming\
**Created:** [October 28, 2003, 6:30am UTC](https://forum.kirupa.com/t/database-performance/34101 "2003-10-28T06:30:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rysolag](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rysolag](https://forum.kirupa.com/u/rysolag)\
**Post date:** [October 28, 2003, 6:30am UTC](https://forum.kirupa.com/t/database-performance/34101/1 "2003-10-28T06:30:51Z")

</div>

I have a question about pulling 1000’s of records from a database and efficiently displaying them.

```
My record set has 5000 records and I want to display it using HTML. It would not be right to make a table with 5000 rows becuase it would take a long time and scrolling would be out of control. So I want to only write the first 50 to the screen and have previous and next buttons to bring up the next or previous set of 50 records. I know this is done all over the net(this site does it with these forums). How do I do this? Are there different options?

```

Thanks,

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 7:30am UTC](https://forum.kirupa.com/t/database-performance/34101/2 "2003-10-28T07:30:21Z")

</div>

if you want 50 recods per page, your should be something like this:

```php
$pageNumber = $_GET['p']-1; // pass the "page number" is the variable "p" to indicate current page
$startAt = $pageNumber*50 // calculate record# to start at, based on page number

$myQuery = "SELECT *";
$myQuery .= "FROM myTable"; 
$myQuery .= "WHERE ID>'$startAt'";
$myQuery .= "LIMIT 50"; //select only 50 records

```

hope that helps 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 7:50am UTC](https://forum.kirupa.com/t/database-performance/34101/3 "2003-10-28T07:50:33Z")

</div>

Thanks ahmed, that does help. But there is still more.

OK, lets say I want to pull all records with a specific UserID and the UserID is not the primary key(i.e. there are a bunch of records for this user). Your method won’t work. Get what I’m saying?

Any solutions? Thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 7:56am UTC](https://forum.kirupa.com/t/database-performance/34101/4 "2003-10-28T07:56:15Z")

</div>

hm… i’ll have to look into that, never done anything like that 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 8:54am UTC](https://forum.kirupa.com/t/database-performance/34101/5 "2003-10-28T08:54:44Z")

</div>

I am using PHP and mySQL…

Could’nt you create a temp table with just the records for the user then use your method?

I don’t know temp tables…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 10:42am UTC](https://forum.kirupa.com/t/database-performance/34101/6 "2003-10-28T10:42:46Z")

</div>

Wouldn’t you just go?:

SELECT \*  
FROM Tables  
WHERE UserID = ‘users\_id’

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 10:54am UTC](https://forum.kirupa.com/t/database-performance/34101/7 "2003-10-28T10:54:31Z")

</div>

cause that would return 1000’s of records when he only needs 50 records

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 10:59am UTC](https://forum.kirupa.com/t/database-performance/34101/8 "2003-10-28T10:59:15Z")

</div>

Ah ok, I’m not totally following… doesn’t your code before do that?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 28, 2003, 11:44pm UTC](https://forum.kirupa.com/t/database-performance/34101/9 "2003-10-28T23:44:06Z")

</div>

no…

$myQuery .= “LIMIT 50”;

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 30, 2003, 12:52am UTC](https://forum.kirupa.com/t/database-performance/34101/10 "2003-10-30T00:52:35Z")

</div>

top
