next page records (done, but a little problem. -OT-)
| From: | Ryan A | Date: | Sat, 03 May 2003 00:50:58 +0000 |
| Subject: | next page records (done, but a little problem. -OT-) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146213@lists.php.net to get a copy of this message | ||
Hi everyone,
Thanks to the links given to me by the kind people here I have findished
"paginating" one of my scripts...I just have one little problem, instead of
using "COUNT" this method is using "mysql_num_rows" as you can imagine if
you have a large amount of records this is not a good solution but somehow I
am unable to implement "COUNT" into this so I am includeing the code below
in its original form for any suggestions from you guys.
How can i take out the mysql_num_rows and add "count" instead?
I have tried doing it by looking at the example here:
http://www.devshed.com/Server_Side/PHP/Paginating/page4.html
but am unable to do so.
If any of you have any ideas please tell me.
Cheers,
-Ryan
(*********** CODE IS BELOW **************)
<?php
require 'config.php';
$connected=mysql_connect ("$hostt", "$userr", "$passs") or die
('I cannot
connect to the database because: ' . mysql_error());
mysql_select_db ("$db");
Print("<table width=90% border=0 align=right>");
print("<tr><td><b>Name</b></td><td><b>Username</b></td><td><b>Password</b></
td><td> </td><td> </td><td> </td></tr>");
$limit = 10;
$query_count = "SELECT * from $tcname";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count); // **** this is what i
want to take out and put "count()"
// ** everything below is just if you are curious...its only the top part
that needs to be changed
if(empty($page))
$page = 1;
$limitvalue = $page * $limit - ($limit);
$database["sql"] = " select * from ".$tcname." order by card_holder_name
LIMIT $limitvalue, $limit";
$result = mysql_query($database["sql"]) or die("Error: " .
mysql_error());
if($result= mysql_query($database["sql"]))
{
while($row = mysql_fetch_row($result))
{
print("This is working but too much code so to make this simple i took it
out");
}
if(mysql_num_rows($result) == 0)
echo("Nothing to Display!");
echo '<tr><td align=center colspan=6><br>';
if($page != 1){
$pageprev = $page-1;
echo("<a href=\"view2.php?page=$pageprev\">PREV</a>
");
}else
echo("PREV ");
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page)
echo($i.": ");
else
echo("<a href=\"view2.php?page=$i\">$i</a> ");
}
if(($totalrows % $limit) != 0){
if($i == $page)
echo($i.": ");
else
echo("<a href=\"view2.php?page=$i\">$i</a> ");
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page+1;
echo(" <a href=\"view2.php?page=$pagenext\">NEXT
</a>");
}else
echo("..");
// mysql_free_result($result);
}}
else{print("Query error: ".mysql_errno().", ".mysql_error()." SQL:
".$database["sql"]);}
echo '</td><tr>';
print("</table>");
?>