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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2008
    Posts
    103
    Thanks
    4
    Thanked 0 Times in 0 Posts

    anybody help me with this php

    i have tried but failed.The buddylist shows all the buddies but i want to make it every page it will show 10 buddies only.I have both of the code but cant combine it properly so if there is anyone who can help me out will be so greatfull for me.





    THE BUDDYLIST CODE:
    Code:
    
    $q = @mysql_query("select * from `buddylist` where `test`='".$user['login']."' and ci='".$ci."' and agreed='".$p."';");
    while($man = @mysql_fetch_array($q)) {
    
    $rs = @mysql_query("select * from `chat_users` where login='".$man['name']."' and `ltime`>'".intval(time()-$offline)."';");
    $d = @mysql_fetch_array($rs);
    
    echo "".$man['name'].",
    <a href=\"./user.php?".SID."&amp;nocache=$nocache&amp;room=$room&amp;m=$n&amp;dblogin=".$man['name']."\">Pm</a>";
    
     
    
    
    
    if ($d=="") { echo " Offline<br/>"; } else { echo " <b>Online</b><br/>"; } }

    THE 10 PERSONS SHOWS EVERY PAGE CODE
    Code:
        if($page=="" || $page<=0)$page=1;
        $noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM kitkat"));
        $num_items = $noi[0]; 
        $items_per_page= 10;
        $num_pages = ceil($num_items/$items_per_page);
        if(($page>$num_pages)&&$page!=1)$page= $num_pages;
        $limit_start = ($page-1)*$items_per_page;
    
        //changable sql
    
            $sql = "SELECT abc, ads, pnd FROM kitkat ORDER BY id DESC LIMIT $limit_start, $items_per_page";
        $items = mysql_query($sql);
    	
        echo mysql_error();
        if(mysql_num_rows($items)>0)
        {
        while ($item = mysql_fetch_array($items))
       {
    		
            echo "$item[1] &#187; ";
            echo "<img src=\"$item[2]\" alt=\"$item[1]\"/><br/>";
        }
        }
        if($page>1)
        {
          $ppage = $page-1;
          echo "<a href=\"abc.php?".SID."&amp;nocache=$nocache&amp;page=$ppage\">&#171;PREV</a> ";
        }
        if($page<$num_pages)
        {
          $npage = $page+1;
          echo "<a href=\"abc.php?".SID."&amp;nocache=$nocache&amp;page=$npage\">Next&#187;</a>";
        }
        echo "<br/>$page/$num_pages<br/>";

    ALL I WANT IS THAT THE 1ST PAGE LIST WILL BE LIKE THE SECOND PAGE 10 PERSONS SHOWS EVERY PAGE.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    What this is called is Pagination. It's quite complex in my opinion.

    http://www.phpfreaks.com/tutorial/basic-pagination
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    Regular Coder
    Join Date
    Nov 2008
    Posts
    103
    Thanks
    4
    Thanked 0 Times in 0 Posts
    can anybody do it for me please it will be so greatful i tried a lot of times but i failed

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    It'd be very rare to find someone to do this for you for free, because it can take quite a long time to do, by studying your own and putting it in.

    You may can hire someone for $20 in the work forums to do it.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #5
    Regular Coder
    Join Date
    Nov 2008
    Posts
    103
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i guess just need to put the sql queries in the right place where i am failing to do i just need a page with every page 10 buddies will show i also even given the buddylist code sql queries just need to be putten those quries in the 2nd page i have given for the list

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    It's super easy to display 10 records, but when you get into auto creating pages, that is the hard part.

    If you know exactly how many records you will have total, you can setup your own pages the way you want them.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #7
    Regular Coder
    Join Date
    Nov 2008
    Posts
    103
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Code:
      if($page=="" || $page<=0)$page=1;
        $noi = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM kitkat"));
        $num_items = $noi[0]; 
        $items_per_page= 10;
        $num_pages = ceil($num_items/$items_per_page);
        if(($page>$num_pages)&&$page!=1)$page= $num_pages;
        $limit_start = ($page-1)*$items_per_page;
    
        //changable sql
    
            $sql = "SELECT abc, ads, pnd FROM kitkat ORDER BY id DESC LIMIT $limit_start, $items_per_page";
        $items = mysql_query($sql);
    	
        echo mysql_error();
        if(mysql_num_rows($items)>0)
        {
        while ($item = mysql_fetch_array($items))
       {
    		
            echo "$item[1] » ";
            echo "<img src=\"$item[2]\" alt=\"$item[1]\"/><br/>";
        }
        }
        if($page>1)
        {
          $ppage = $page-1;
          echo "<a href=\"abc.php?".SID."&amp;nocache=$nocache&amp;page=$ppage\">«PREV</a> ";
        }
        if($page<$num_pages)
        {
          $npage = $page+1;
          echo "<a href=\"abc.php?".SID."&amp;nocache=$nocache&amp;page=$npage\">Next»</a>";
        }
        echo "<br/>$page/$num_pages<br/>";

    This one is the system to show 10 records each time and next page will be the same page just page will be $npage thats all i want i just need to put the sql queries in this codes perfectly then it will work i hope so please help me .


    and sorry for my bad english i know it will be hard for everyone 2 understand


  •  

    Posting Permissions

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