473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Limit number of results to 10 with next button?

117 100+
How can i limit the number of results to 10 and have a Next >> button appear or << Back on the bottom if there is more than 10 results?
Because as of now it's only 7 members but it will soon be 400 lol

And have it fit into this code...
[PHP]<?
$sql = "select login, gender, aboutme from users";
$_res = mysql_query($sql);
while( $_row = mysql_fetch_assoc($_res) )
{
echo '<font face="Geneva size="-2">', '<font color="#FF0000">', $_row['login'], '</font>', '&nbsp;&nbsp;&nbsp;', '<font color="#FF0000">', $_row['gender'], '</font>', '&nbsp;&nbsp;&nbsp;', '<img src="images/start.gif" width="14" height="8" />', '<font color="#003366">', $_row[aboutme], '</font>', '<img src="images/end.gif" width="14" height="8" />', '</FONT>', '<hr size="1" />';
}
mysql_free_result($_res);
?>[/PHP]
Aug 27 '07 #1
6 2693
do something like this:

[PHP]
//...
$bl=mysql_real_escape_string($_GET["bl"]); //bottom limit
$ul=mysql_real_escape_string($_GET["ul"]); //upper limit, that is how manu rows to select

$sql="SELECT login, gender, aboutme FROM users LIMIT $bl,$ul";
$_res=mysql_query($sql)
//the rest is the same like your code...
//...
mysql_free_result($res);

echo '<a href="thisPage.php?bl='.($bl-$ul).'&ul=$ul">&lt;&lt;back</a> ';
echo '<a href="thisPage.php?bl='.($bl+$ul).'&ul=$ul">next&g t;&gt;</a>';
//...
[/PHP]

if you want to see 10 by 10 results you just link to it like:
href="thisPage.php?bl=0&ul=10"
to get first 10 results...
Aug 27 '07 #2
Breana
117 100+
Nope, just an empty page, and if i change a few lins it works but adds a next next to all names not a the bottom and it keeps trying to url me to a missin page..

I think i'll just pass on this till i get an easy fix or a better way to do it thanx though.
Aug 27 '07 #3
Atli
5,058 Expert 4TB
This is a simple thing to do.

You simply need to know how many entries you want per page, how many entries there are total and what page the user is currently viewing.
Then you can simply calculate the number of pages there are and which one your links / buttons should navigate to.

Post your attempts if you encounter any problems and we will do our best to help, but do not expect us to write your code for you.
Aug 27 '07 #4
Breana
117 100+
Is that what you think of me? hoping others will write the code for me no.
i have been working with my own and his tring to learn, man people are so rude!

I ant no code genius like you.
And so you know i did almost this my self and it worked the first try!
[PHP]echo '<font face="Geneva size="-2">', '<font color="#FF0000">', $_row['login'], '</font>', '&nbsp;&nbsp;&nbsp;', '<font color="#FF0000">', $_row['gender'], '</font>', '&nbsp;&nbsp;&nbsp;', '<img src="images/start.gif" width="14" height="8" />', '<font color="#003366">', $_row[aboutme], '</font>', '<img src="images/end.gif" width="14" height="8" />', '</FONT>', '<hr size="1" />';[/PHP]

Thanks to the help of others.. i am learning.
Aug 27 '07 #5
Atli
5,058 Expert 4TB
Is that what you think of me? hoping others will write the code for me no.
i have been working with my own and his tring to learn, man people are so rude!
I meant to offense and I am most certainly not trying to be rude. This is just one of those things I would rather say to often then to rarely.
Aug 28 '07 #6
Breana
117 100+
Well i got it to limit the number of results to 10 in my code, but the next buttons just don't work out.

I i created a link, View Full Results >>
and linked it to a full_results.php file with no limit so at least it looks nice.
I will keep working on it but when i learn more i will alter it :)
Aug 29 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: krystoffff | last post by:
Hi I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok. But for the first page, I need to run the...
5
by: Nick | last post by:
Is there a (better) way to get the toal number of results from a query but still limit them with a LIMIT clause. For example, in a Google search result, it displays 1-100 of 10,000,000 results. Do...
4
by: emily_g107 | last post by:
Hi, I need to limit results in the following query type: ...
0
by: D. Dante Lorenso | last post by:
I need to know that original number of rows that WOULD have been returned by a SELECT statement if the LIMIT / OFFSET where not present in the statement. Is there a way to get this data from PG ?...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
4
by: Haydnw | last post by:
Hi, I'd like to put a load of database results (several rows for 5 fields) into a two-dimensional array. Now, this may be a really stupid question, but can someone give me a pointer for how to...
1
by: lalitha1024 | last post by:
Hi, In my Asp.net project, i am using datagrid to show results, whic included custom sorting, custom paging and option to select number o rows per page using radio button list. it works very fine....
2
by: MLH | last post by:
HowManyMore = InputBox(MyString, "How Many More?", "3") The above line results in an InputBox displaying that has an X button in the upper right corner. And next to it, there's a ? button (for...
3
by: markon | last post by:
Hi, I would like to run few lines of code and limit the time. If the procedure would not be finished say in 1000ms I would like to stop processing it. Unfortunately I do not know where to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.