Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts

    link problem [1][2]-----

    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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    De gustibus non est disputandum.

  • #3
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    $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"] -) * $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:
    PHP Code:
    for ($i=1$i<=$pages$i++) 
        echo 
    "<left><a href=test.phtml?page=$i> [$i] </a> "

  • #5
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

    Code:
    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)

    Code:
    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.
    De gustibus non est disputandum.

  • #7
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry for spelling mistakes i will be careful whil hitting reply
    well i am looking for version (a) not (b)

    thanks alot

  • #8
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #10
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    De gustibus non est disputandum.

  • #12
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    PHP Code:
    $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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •