Paginate from group by
6 Message(s) by 3 Author(s) originally posted in php programming
| From: joanna |
Date: Sunday, October 28, 2007
|
I'm having some difficulty paginating from the $_GET
variable ,
because in this
instance the
string being passed is of a
group by
query (one letter). Currently I'm limiting the results using limit,
Here's what I currently have and it works just fine at
display ing, I
just need to add pagination.
<?php
if( !isset( $_GET['title'] ) )
{
print 'No Record was Selected';
}
else
{
$query = mysql_query("SELECT ID,Title FROM table WHERE Title LIKE
'" . $_GET['title'] . "%' LIMIT 0, 100")or die(mysql_error());
}
if( mysql_num_rows($query) == 0 )
{
echo 'Sorry no record s';
}
else
{
while($row = mysql_fetch_array($query ))
{$title=htmlspecialchars($row['Title']);
echo "<td><a href=\"page2.php?title=" .$title. "\"> $title
</a></td>
\n
<br>";
?>
| From: bmichel |
Date: Sunday, October 28, 2007
|
If I understand your problem correctly; you're having problem
distributing the
SQL query on several pages.
By using ORDER BY, you can keep
track of what was displayed already.
SELECT ID,Title
FROM table
WHERE Title LIKE '" . $_GET['title'] . "%'
ORDER BY title
LIMIT 0, 100
Depending on how many results you want to display per page (let's say
100). You can modify the LIMIT. That is for page 1 'LIMIT 0, 100', for
page 2 'LIMIT 100, 200' and so on
echo "<td><a href=\"page2.php?title=" .$title. "\"> $title</a></td>
This here looks like a bad
design idea. You should instead have a
variable (which you can pass through $_GET), which tells you which
page you're on.
$params = "?title=" . $title . "&page=" . $page;
Hope this helps
| From: joanna |
Date: Sunday, October 28, 2007
|
wrote in message:
If I understand your problem correctly; you're having problem
distributing the SQL query on several pages.
By using ORDER BY, you can keep track of what was displayed already.
SELECT ID,Title
FROM table
WHERE Title LIKE '" . $_GET['title'] . "%'
ORDER BY title
LIMIT 0, 100
Depending on how many results you want to display per page (let's say
100). You can modify the LIMIT. That is for page 1 'LIMIT 0, 100', for
page 2 'LIMIT 100, 200' and so on
echo "<td><a href=\"page2.php?title=" .$title. "\"> $title</a></td>
This here looks like a bad design idea. You should instead have a
variable (which you can pass through $_GET), which tells you which
page you're on.
$params = "?title=" . $title . "&page=" . $page;
Hope this helps
It kind of helps, the order by is something that was needed. However,
maybe I was not clear, but I'm having a tough time trying to paginate
the rest of the results as in a "next" and "previous"
link at the
bottom. The results are in the thousands and doing a manual page for
each 100 results'd be too much.
| From: joanna |
Date: Sunday, October 28, 2007
|
wrote in message:
If I understand your problem correctly; you're having problem
distributing the SQL query on several pages.
By using ORDER BY, you can keep track of what was displayed already.
SELECT ID,Title
FROM table
WHERE Title LIKE '" . $_GET['title'] . "%'
ORDER BY title
LIMIT 0, 100
Depending on how many results you want to display per page (let's say
100). You can modify the LIMIT. That is for page 1 'LIMIT 0, 100', for
page 2 'LIMIT 100, 200' and so on
echo "<td><a href=\"page2.php?title=" .$title. "\"> $title</a></td>
This here looks like a bad design idea. You should instead have a
variable (which you can pass through $_GET), which tells you which
page you're on.
$params = "?title=" . $title . "&page=" . $page;
Hope this helps
It kind of helps, the order by is something that was needed. However,
maybe I was not clear, but I'm having a tough time trying to paginate
the rest of the results as in a "next" and "previous" link at the
bottom. The results are in the thousands and doing a manual page for
each 100 results'd be too much.
| From: Jerry Stuckle |
Date: Sunday, October 28, 2007
|
wrote in message:
wrote in message:
If I understand your problem correctly; you're having problem
distributing the SQL query on several pages.
By using ORDER BY, you can keep track of what was displayed already.
SELECT ID,Title
FROM table
WHERE Title LIKE '" . $_GET['title'] . "%'
ORDER BY title
LIMIT 0, 100
Depending on how many results you want to display per page (let's say
100). You can modify the LIMIT. That is for page 1 'LIMIT 0, 100', for
page 2 'LIMIT 100, 200' and so on
echo "
<td><a href=\"page2.php?title=" .$title. "\"> $title
</a></td>
This here looks like a bad design idea. You should instead have a
variable (which you can pass through $_GET), which tells you which
page you're on.
$params = "?title=" . $title . "&page=" . $page;
Hope this helps
It kind of helps, the order by is something that was needed. However,
maybe I was not clear, but I'm having a tough time trying to paginate
the rest of the results as in a "next" and "previous" link at the
bottom. The results are in the thousands and doing a manual page for
each 100 results'd be too much.
No, please reread bmichel's comments. His answer is correct on how you
should be paginating your results.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS
Computer Training Corp.
jstucklex@xxxxxxxxxxx
==================
| From: bmichel |
Date: Sunday, October 28, 2007
|
wrote in message:
wrote in message:
wrote in message:
If I understand your problem correctly; you're having problem
distributing the SQL query on several pages.
By using ORDER BY, you can keep track of what was displayed already.
SELECT ID,Title
FROM table
WHERE Title LIKE '" . $_GET['title'] . "%'
ORDER BY title
LIMIT 0, 100
Depending on how many results you want to display per page (let's say
100). You can modify the LIMIT. That is for page 1 'LIMIT 0, 100', for
page 2 'LIMIT 100, 200' and so on
echo "
<td><a href=\"page2.php?title=" .$title. "\"> $title
</a></td>
This here looks like a bad design idea. You should instead have a
variable (which you can pass through $_GET), which tells you which
page you're on.
$params = "?title=" . $title . "&page=" . $page;
Hope this helps
> It kind of helps, the order by is something that was needed. However,
> maybe I was not clear, but I'm having a tough time trying to paginate
> the rest of the results as in a "next" and "previous" link at the
> bottom. The results are in the thousands and doing a manual page for
> each 100 results'd be too much.
No, please reread bmichel's comments. His answer is correct on how you
should be paginating your results.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@xxxxxxxxxxx
==================
Here's how your
code might look like:
<?php
$record_per_page = 100;
$title = $_GET['title'];
$page = $_GET['page']; // first page is 1 or not set, second page is
2,...
if(!isset($title)) {
echo 'No Record was Selected';
exit(); // this will stop the execution, modfiy as needed
}
if (!isset($page)) {
$page = 1;
}
// Record to look up.
$start_limit = ($page - 1) * $record_per_page;
$end_limit = $page * $record_per_page;
$query = mysql_query("SELECT ID,Title
FROM table WHERE Title LIKE'$title%'
ORDER BY Title
LIMIT $start_limit, $end_limit")
or die(mysql_error());
if( mysql_num_rows($query) == 0) {
echo 'Sorry no records';
exit();
}
while($row = mysql_fetch_array($query )) {
$doc_title = htmlspecialchars($row['Title']); // stores the title
of each row.
// I'm not sure what you're doing after that, so I'm leaving that
for you. // Links for the pagination.
$next_link = "index.php?title=$title&page=" . ($page + 1);
$prev_link = "";
if ($page != 1) {
$prev_link = "index.php?title=$title&page=" . ($page - 1);
}
?>Some notes:
Replace 'index.php' by the name of the page the script is executed on.
You might need to do some checking on $next_link also in order not to
get to a page where no results will appear.
exit() here will just stop the execution, so replace it by whatever
you need; or get back to your if - else nested solution.
Next Message: Session or browser problem??
Blogs related to Paginate from group by
[PHP Classes] PHP Classes: Weekly newsletter of Wednesday - 2007-10-10
Latest regional
PHP User
Group submissions. Innovation award results. Latest blog trackback links
.... If you make part of a regional
PHP User
Group not listed here, submit your user
group. Contents. Innovation award results
...
jsp login examples
... tutorial jsp pdf tutorials jsp pdfs jsp performance jsp performance issues jsp performance tips jsp performance tuning jsp
php jsp
php asp jsp
php asp comparison jsp
php compare jsp
php comparison jsp
php hosting jsp
php performance
...
Phpmyadmin-trk-bugs Digest, Vol 17, Issue 26
Server is Linux with MySQl 4.1.22/
php 4.4.7/phpMyAdmin 2.11.1. If a database has more tables than the MaxTableList value, a
pagination menu is created, however it isn't functional. All tables in the database are listed regardless of the
...
Im developing a PHP web application and I have a query like this ...
"SELECT groups.id, name, level, relations.userid FROM groups LEFT JOIN relations ON groups.id = relations.groupid
GROUP BY nombre , how can i make that when it groups the results, it shows on userid the user i want instead of the 1st
...
PHP framework comparison #2
Modular architecture; GUI and data internationalisation; Application level record locking; Minimum amount of required coding; Fully customisable; Themable; Template driven; Database abstraction; GUI abstraction; User-based,
group-based,
...
Using ADOdb with PHP and Oracle: an advanced tutorial
Provides great speedups for SQL involving complex where,
group-by and order-by clauses. Popularity Yes, part of PEAR release Yes, many open source projects are using this software, including PostNuke, Xaraya, Mambo, Tiki Wiki.
...