Re: How to number pages with results?
| From: | Chris Lee | Date: | Sun, 03 Dec 2000 05:58:34 +0000 |
| Subject: | Re: How to number pages with results? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28466@lists.php.net to get a copy of this message | ||
If your using MySQL (most SQL's use LIMIT)
$query = "SELECT * FROM product WHERE ... LIMIT $pos , $howmany";
ie.
<?
if (!isset($search))
$search = '';
if (!isset($pos))
$pos = 0;
$howmany = 5;
$forpos = $pos + $howmany;
$bakpos = $pos - $howmany;
$query = "SELECT count(*) FROM product WHERE name LIKE '%$search%'";
$result = mysql_db_query("cooldragons", $query);
$r = mysql_fetch_array($result);
$maxnum = $r["count(*)"];
$query = "SELECT * FROM product WHERE name LIKE '%$search%' LIMIT $pos,
$howmany";
$result = mysql_db_query("cooldragons", $query);
echo "<form method=post action='$PHP_SELF'>\n";
echo "<input type=text name=search value='$search'>\n";
echo "<input type=submit>\n";
echo "</form>\n";
echo "<br>I found $maxnum products<br><br>\n";
while ( $r = mysql_fetch_array($result) )
{
echo "product {$r["name"]} <br>\n";
}
echo "<br>\n";
if ($bakpos >= 0)
echo "<a href='$PHP_SELF?search=$search&pos=$bakpos'>BACK</a>
\n";
echo "<a href='$PHP_SELF?search=$search&'>HOME</a> \n";
if ($forpos < $maxnum)
echo "<a href='$PHP_SELF?search=$search&pos=$forpos'>NEXT</a>
\n";
?>
Now this is a super basic script you really HAVETO implemet your own
error checking with
if (mysql_errno())
echo mysql_error();
more information about these functions at
http://php.net/manual/function.mysql-error.php
http://php.net/manual/function.mysql-fetch-array.php
http://php.net/manual/function.mysql-db-query.php
Chris Lee
Mediawaveonline.com
In article <MABBIBFOCGFGDFPIEEDPGEHACBAA.kurin@volny.cz>, kurin@volny.cz
wrote:
> Does anybody know how I can number pages with looked up results?
>
> For example I wrote out items from array on page, but there's hundreds
> of items. How can I to divide it for another pages. There must be links
> for next pages and previous pages.
>
> have you some ideas?
>
> Thank you very much.
>
> Jura Nemec
> ---
> Odchozí zpráva neobsahuje viry. Zkontrolováno antivirovým systémem AVG
> (http://www.grisoft.cz). Verze: 6.0.215 / Virová báze: 101 - datum
> vydání: 16.11.2000
>
>