Page 1 of 1
link problem [1][2]-----
Posted: Tue Sep 16, 2003 6:16 am
by zuzupus
hi,
form below piece of code i try to get the next page when 3 rows shown in table ,once user enter 4th row he will get page [1][2][3]
...and so on same liek this forum
so i jsut counted the rows from table t_emp where user
Code: Select all
$Qpages=mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM t_emp WHERE user = $session->sys_pk"));
$pages=ceil($Qpages[0]);
$offset=($HTTP_GET_VARS["page"]*3)-3;
$result = mysql_query(" SELECT
bah balh from
t_emp order by id DESC LIMIT $offset,3");
then here is some problem
<? for ($i=3; $i<=$pages; $i++) echo "<left><a href=test.phtml?page=$i> [$i] </a> ";?>
as now what happening once user submit the form it shows [1] [2] [3] and so on
if anybody figure it out be appreciated and anything not able to understand plz let me know
regards
Posted: Tue Sep 16, 2003 7:59 am
by SantaGhost
i dont fully understand the problem, it might help to give the url of the script.
you want the following:
print 4 rows,
print navigation
Code: Select all
<?
for($i=3; $i<=$pages; $i++){
$page = $_GET["page"] + $i;
echo "<left><a href=test.phtml?page=$page> [$page] </a> ";
}
?>
Posted: Tue Sep 16, 2003 8:22 am
by zuzupus
this wont works sorry to say that and for not be clear from ym side
anyway
i want the rows from t_emp <to be shown three to a page? So if there were say 7 rows <then initially the user would see rows 1-3 on screen with <links to page 2 and 3, page 2 would show rows 4-6 and <page 3 would show row 7?
once he submit 4th row then
[1][2]
then [2]
have 4ht row and [1] have 1-3 rows
hope this is clear
thnks
Posted: Tue Sep 16, 2003 9:00 am
by SantaGhost
heres what ive come up with, if rows are 4 two links are displayed, if rows are 7 three links are displayed ect.
you should be able to build in that if page==currentpage echo [$page] instead of a link.
Code: Select all
<?php
$rows = 7;
$count = 0;
for($i=1; $i<=$rows; $i++){
if($i%3 == 0){
$page = $i/3;
echo "<left><a href=test.phtml?page=".$page."> [".$page."] </a> ";
$count = $count+3;
}
}
if($rows-$count > 0){
$page++;
echo "<left><a href=test.phtml?page=".$page."> [".$page."] </a> ";
}
?>
Posted: Tue Sep 16, 2003 10:21 am
by zuzupus
thanks Santa well i want somethign like this
Code: Select all
1. Page: 2. Page
------- ---------
aaa ddd
bbb
ccc
1 ї2] ї1] 2
Where the [2] stands for a link with the number as text, and 1 only means a number without link (same applies to [1] and 2).
Code: Select all
$recs_per_page = 3;
$Qrecs=mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM t_emp WHERE user = $session->sys_pk"));
$num_records = $Qrec[0];
$num_pages = ceil($num_records / $recs_per_page);
if($num_pages == 0) { $num_pages = 1; }
$page = isset($HTTP_GET_VARS["page"])?$HTTP_GET_VARS["page"]:0;
$page = preg_replace('/\D/','',$page);
if($page < 1) { $page = 1; }
if($page > $num_pages) { $page = $num_pages; }
$offset = ($page - 1) * $recs_per_page;
<?
for ($i=1; $i<=$num_pages; $i++) echo "<right><a href=test.phtml?page=$i> [$i] </a> ";
?>
but everytime i have to clcik [1] to see 3 rows
hope u have any idea
thanks
Posted: Tue Sep 16, 2003 10:41 am
by SantaGhost
i know what you mean, it would have helped a lot if you could have given the link to the script...
i think you want something like this:
http://62.163.148.188/gallery.php
try this instead of your current for loop:
Code: Select all
<?php
for ($i=1; $i<=$num_pages; $i++){
if($page == $i){
echo "<right>[$i] ";
}else{
echo "<right><a href=test.phtml?page=$i> [$i] </a> ";
}
}
?>
Posted: Wed Sep 17, 2003 3:20 am
by zuzupus
sorry its not working when i used ur code but the link u send me gallery.php i also want soemthing like that
hope you understand my problem
this is for 4 records when more then it will increase
1. Page: 2. Page
------- ---------
aaa ddd
bbb
ccc
1 [2] [1] 2
thansk in advance
Posted: Wed Sep 17, 2003 7:46 am
by zuzupus
santa im back actually its my mistake actually i forget s in
$Qrec[0]; it should be $Qrecs[0]
it works fine but dont no how to get 1[2] in first page and second page must be [1]2
how to deal with this one
plz have a look at this
http://172.16.0.100/scripts/test.phtml
<?
if($num_pages > 1)
{
for ($i=1; $i<=$num_pages; $i++) echo "<left><a href=test.phtml?page=$i> [$i] </a> ";
}
?>
regards
Posted: Wed Sep 17, 2003 9:25 am
by SantaGhost
this works for shure
Code: Select all
<?
if($num_pages > 1)
{
for ($i=1; $i<=$num_pages; $i++){
if(!isset($_GET["page"])){ $_GET["page"] = 1; }
if($_GET["page"] != $i){
echo "<left><a href=test.phtml?page=$i> [$i] </a> ";
}else{
echo "<left>[$i] ";
}
}
}
?>
Posted: Wed Sep 17, 2003 9:30 am
by zuzupus
excellent thanks alot now it works the way i want
cheers
