Can anyone help me out by either telling me how to get to the result i
need or by pointing me to some documentation about the following question:
A certain query to a database give me eg 100 results:
$query = "select id, name, addr1, addr2, city from mytable where id="
..$id;
$connection = mysql_connect(etc etc)
....
Then:
<table>
while ($result = mysql_fetch_array($connection)){
<tr>
<td>echo $result['name]; </td>
<td>echo $result['addr1']; </td>
</tr>
}
</table>
This all works well, but will give me all eg 100 results in one webpage.
What i want however is max 10 results per page, and then a link in the
bottom of a page with "next" reloading that page but then displaying
result 11-20 etc etc.
Now i've been puzzling about that the last couple of days but i just can't
get that to work. Anyone any suggestions / links / idea?
tia.
Joe 8 3697
In article <pa****************************@home.nl>,
"joe" <wa*****@home.nl> wrote: This all works well, but will give me all eg 100 results in one webpage. What i want however is max 10 results per page, and then a link in the bottom of a page with "next" reloading that page but then displaying result 11-20 etc etc. Now i've been puzzling about that the last couple of days but i just can't get that to work. Anyone any suggestions / links / idea?
for first 10 results:
SELECT ... FROM ... WHERE ... LIMIT 0,10
for results 11-20:
SELECT ... FROM ... WHERE ... LIMIT 10,10
for results 21-30:
SELECT ... FROM ... WHERE ... LIMIT 20,10
etcetera. You can put the 'starting number' (first number of the LIMIT,
the number of rows to be skipped) somewhere in your 'next page' URL to
build your query, for example, for the "LIMIT 20,10" query:
<a href="script.php?startnr=20">next page</a>
the value for 'previous page' links would be $_GET['startnr'] - 10, for
'next page' links it would be $_GET['startnr'] + 10. The value '10' for
'number of results per page' could be a constant defined somewhere. You
get the idea.
JP
--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
On Mon, 22 Sep 2003 21:07:25 +0200, Jan Pieter Kunst wrote: In article <pa****************************@home.nl>, "joe" <wa*****@home.nl> wrote:
This all works well, but will give me all eg 100 results in one webpage. What i want however is max 10 results per page, and then a link in the bottom of a page with "next" reloading that page but then displaying result 11-20 etc etc. Now i've been puzzling about that the last couple of days but i just can't get that to work. Anyone any suggestions / links / idea?
for first 10 results:
SELECT ... FROM ... WHERE ... LIMIT 0,10
for results 11-20:
SELECT ... FROM ... WHERE ... LIMIT 10,10
for results 21-30:
SELECT ... FROM ... WHERE ... LIMIT 20,10
etcetera. You can put the 'starting number' (first number of the LIMIT, the number of rows to be skipped) somewhere in your 'next page' URL to build your query, for example, for the "LIMIT 20,10" query:
<a href="script.php?startnr=20">next page</a>
the value for 'previous page' links would be $_GET['startnr'] - 10, for 'next page' links it would be $_GET['startnr'] + 10. The value '10' for 'number of results per page' could be a constant defined somewhere. You get the idea.
Yep thanx got the idea, and and even works:) However i haven't been totally
clear in the first post: I posted a part of the problem I have and I used
MySql as one of them. But i have to make that query on both a mysql server
and on a sybase server. And sybase don't know the "LIMIT" option, and from
what i've read in me search for a solution, not an equivalent for that
either which i can use from within php. So something like:
$query = "set rowcount 5 select name, addr from sometable where id=" .$id
doesn't work. You know of any options for that as well?
again tia,
Joe
Jan Pieter Kunst wrote: In article <pa****************************@home.nl>, "joe" <wa*****@home.nl> wrote:
This all works well, but will give me all eg 100 results in one webpage. What i want however is max 10 results per page, and then a link in the bottom of a page with "next" reloading that page but then displaying result 11-20 etc etc. Now i've been puzzling about that the last couple of days but i just can't get that to work. Anyone any suggestions / links / idea?
for first 10 results:
SELECT ... FROM ... WHERE ... LIMIT 0,10
for results 11-20:
SELECT ... FROM ... WHERE ... LIMIT 10,10
for results 21-30:
SELECT ... FROM ... WHERE ... LIMIT 20,10
etcetera. You can put the 'starting number' (first number of the LIMIT, the number of rows to be skipped) somewhere in your 'next page' URL to build your query, for example, for the "LIMIT 20,10" query:
<a href="script.php?startnr=20">next page</a>
the value for 'previous page' links would be $_GET['startnr'] - 10, for 'next page' links it would be $_GET['startnr'] + 10. The value '10' for 'number of results per page' could be a constant defined somewhere. You get the idea.
JP
I've had kind of the same question. I know how to do the limiting and
all, but my question lies in the count() function.
I'm assuming to find out how many total pages there would be, I'd have
to count the total number of rows returned and divide by how many I plan
on having displayed per page. How do I do that count?
I'm pretty sure I'll have to do two queries. One to get the total
number of rows returned, and another that includes the LIMIT. I'd be
very much obliged if someone could post a quick code excerpt on how to
do that.
TIA,
Jay
"joe" <wa*****@home.nl> wrote in message
news:pa****************************@home.nl... Can anyone help me out by either telling me how to get to the result i need or by pointing me to some documentation about the following question:
A certain query to a database give me eg 100 results:
$query = "select id, name, addr1, addr2, city from mytable where id=" .$id; $connection = mysql_connect(etc etc) ...
Then: <table> while ($result = mysql_fetch_array($connection)){ <tr> <td>echo $result['name]; </td> <td>echo $result['addr1']; </td> </tr> } </table>
This all works well, but will give me all eg 100 results in one webpage. What i want however is max 10 results per page, and then a link in the bottom of a page with "next" reloading that page but then displaying result 11-20 etc etc. Now i've been puzzling about that the last couple of days but i just can't get that to work. Anyone any suggestions / links / idea?
tia. Joe http://www.devshed.com/Server_Side/P...ing/page1.html
On Mon, 22 Sep 2003 16:28:50 -0500, Jay Moore wrote: I've had kind of the same question. I know how to do the limiting and all, but my question lies in the count() function.
I'm assuming to find out how many total pages there would be, I'd have to count the total number of rows returned and divide by how many I plan on having displayed per page. How do I do that count?
I'm pretty sure I'll have to do two queries. One to get the total number of rows returned, and another that includes the LIMIT. I'd be very much obliged if someone could post a quick code excerpt on how to do that.
TIA, Jay
<?php
$link = mysql_connect("localhost", "someuser", "somepass");
mysql_select_db("db", $link);
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
$max_per_page = 10;
$no_of_pages = $num_rows / $max_per_page;
?>
or s/mysql/sybase in case you're using sybase
hth.
On Tue, 23 Sep 2003 00:05:10 +0200, joe wrote: On Mon, 22 Sep 2003 14:31:43 -0700, Steve Edwards wrote:
http://www.devshed.com/Server_Side/P...ing/page1.html
Yep nice tutorial but that's mysql and based on limiting the query with "LIMIT" which is not a sybase statement..
Forget that previous post you answered to a thread where i dind't mention
(yet) that i needed that "limiting" on a sybase server as well. Sry :)
In article <pa****************************@home.nl>,
"joe" <wa*****@home.nl> wrote: But i have to make that query on both a mysql server and on a sybase server. And sybase don't know the "LIMIT" option, and from what i've read in me search for a solution, not an equivalent for that either which i can use from within php. So something like: $query = "set rowcount 5 select name, addr from sometable where id=" .$id doesn't work. You know of any options for that as well?
No, sorry, I never used Sybase so I can't help you with that.
JP
--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: tnhoe |
last post by:
Hi,
<Form method='post' action="next.htm?btn="+"this.myform.myobj.value">
What is the correct syntax for above ?
Regards
Hoe
|
by: John Smith |
last post by:
I have more than 4,000 pieces of email in my Yahoo account. I
would like to write a program to download them all. In order to
write such a program, I need to know a few things.
1. After I fill...
|
by: domcatanzarite |
last post by:
How would one create a button that on click advances the form to the
next "non recurring record" as opposed to the next record.
The field the button needs to que from has groups of duplicate...
|
by: tommak |
last post by:
It's a dream of human beings to build machines that can think and
behave like human beings. The most important part of of such a
machine is an artificial mind that can emulate the cognitive...
|
by: Dale |
last post by:
Access 2000
I am trying to check the form to be sure that required fields are
entered. For each required field (Control) I have set the tag property
to "1". I am trying to loop through all...
|
by: Nick Gilbert |
last post by:
Hi,
I'm using the asp:Wizard control and on some of the steps, I would only
like the user to be able to progess to the next step by clicking an
image button. Therefore I would like to be able to...
|
by: craig.keightley |
last post by:
I am trying to get the next row within a loop for a script i am
developing...
I need to display a final table row within the table that i have
displayed on the page, but i only want to show it...
|
by: karen987 |
last post by:
Can someone please explain what code i need to add to keep a set of links at the bottom of a pop up window?
I need it in a page where people post comments. It is a pop up window, of about 500x400...
|
by: Ajm113 |
last post by:
Ok, I want to make something that checks the other page and sees if their are anymore results on it. If not then do not show the "Next" link. How is this done? Also how do I have it so it will...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |