...

View Full Version : link problem [1][2]-----



zuzupus
09-16-2003, 12:15 PM
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
[PHP]
$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>&nbsp";?>
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

mordred
09-16-2003, 01:31 PM
Huh?
I'm afraid you lost me with your very confusing post. What is the problem, actually? You say that you want a page to be shown or some links to be written, and something is going wrong - but what exactly?

If there's a problem with your SQL query, first try it in phpMyAdmin and if it works, put it in your script, and check mysql_error() to see if an error ocurred.

zuzupus
09-16-2003, 01:41 PM
thanks the query works fine i checked in phpmyadmin and sorry for confusion

i can tell u more clearly

let say there is table for user marc and now he logins and get form
so when he submit the form 3 times by submitting the details let say the below values shown in form once he pushed submit button

aaa
bbb
cccc
and after this when he try to enter fourt detail he will get his fourth detail on second page let say ddd
he get ddd in [2] and on [1] when he clciks he get above info

hope this is clear i think the problem is in for loop but unable to rectify now what happening in posted code after

aaa
it shows [2][3]----
so u get detaisl bbb ccc ddd on 2nd

hope this is clear and sorry for confusion

regards

ConfusedOfLife
09-16-2003, 02:37 PM
Well, I thing there's something wrong with your for loop, first of all you're not showing the info anywhere (I mean those aaa,bbb and ccc) and you're only trying to show the number of pages, right? So, let's make some changes:



$max_show = 3;
$Qpages=mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM t_emp WHERE user = $session->sys_pk"));
$pages=ceil( $Qpages[0] / $max_show );
$offset = ($HTTP_GET_VARS["page"] -1 ) * $max_show;
$result = mysql_query(" SELECT
bah balh from
t_emp order by id DESC LIMIT $offset,$max_show");


Acutally the only change that was necessary (if I didn't want to do what I liked myself!) is the line that you populate $pages. Now for showing page indices you can:


for ($i=1; $i<=$pages; $i++)
echo "<left><a href=test.phtml?page=$i> [$i] </a> ";

zuzupus
09-16-2003, 02:52 PM
thanks alot but i have to clcik[1] to see first 3 rows to see

let say i entered 3 rows and when enterd 4th row let say ddd
aaa
bbb
ccc

then only it goes [1][2]
so on[1] [2]
aaa ddd
bbb
ccc

but now i have to click [1] everytime to see 3 rows

mordred
09-16-2003, 03:50 PM
Isn't that what you asked for? To get this straight: You want only a certain maximum number of rows to be shown to the user. But the fashion could be either a)



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).

Or should it be b)



1. Page: 2. Page
------- ---------
aaa bbb
bbb ccc
ccc ddd
1 [2] [1] 2


So you always see the maximum number of rows. From your first description I would say you meant version a), but your last post suggests to me you rather want version b) to happen. Which one is it?

BTW, please do some minimal spelling/grammar check before hitting the reply button. There's a preview button to see how your post gets formatted. Your posts are really hard to read.

zuzupus
09-16-2003, 03:55 PM
sorry for spelling mistakes i will be careful whil hitting reply
well i am looking for version (a) not (b)

thanks alot

SDP2006
09-17-2003, 12:48 AM
:)

ConfusedOfLife
09-17-2003, 08:16 AM
I can't understand, I'm completely lost in here. I think what I wrote works, and I also think you shouldn't click on the 1 to see the first page, because if it's the first time that you're openning the page (you're initiating the page), then $offset should be zero, and you get the first 3 records. I don't understand the problem in here, what's wrong with the code that you say it doesn't work? Also I think you should show the number all pages in each page, because when the number grows, let's say 200 pages, then you have to count from 1 to 200 that's pretty ugly. You should rather show the numbers in chunks, like what these forums do, and for doing that, you need to use another $offset variable for the whole number of your pages. Anyways, try to explain what's exactly wrong and what you get on your monitor. And finally a simple, rather stupid question, but did you try my code and it didn't work?

zuzupus
09-17-2003, 09:23 AM
sorry that u didnt understand and late reply from my side
frankly speaking i tried ur code then everytime i have to click on [1] to see the 3 records

well i tried something like this

$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;
then used your if block then it works fine anyway thanks alot

regards

mordred
09-17-2003, 09:41 AM
Uhm... ConfusedOfLifes code did not contain any if-blocks, so I'm not sure what you are refering to right now. But judging from your last sentence, I figure the issue is resolved and everything works fine for you? :confused:

ConfusedOfLife
09-17-2003, 06:59 PM
You are welcome, these forums really need a link called "Resolved" to mark a thread resolved (like www.phpbuilder.com).

Anyways, I think you can optimize this line a little bit:


$page = isset($HTTP_GET_VARS["page"])?$HTTP_GET_VARS["page"]:0;

// It could be:
$page = intVal($HTTP_GET_VARS["page"]);


Then it gets zero if it wasn't set! Also don't forget to chunk the number of your pages. You might get lots of pages and then showing them all to ppl is rather ugly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum