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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pagination Updating Every Post In Database?

    Hello,

    I am making a Group feature similar to the one Facebook has, What I am trying to do is add a pagination to the comments so there is not so many comments on the one status update displaying so far so good besides one thing When the user clicks next it will change every post on the group to the second page :/

    How can I modify the below code to only update a certain post that has had the next clicked.

    Here's the code


    PHP Code:
    <body>


    <?php 





    ?>








    <?php 
    require_once ("/../core/connection.php");
    require_once (
    "/../core/group_functions.php");


        
      
     
      
            
    $fetch_clan_posts_query $db->query("SELECT * FROM " TABLE_PREFIX "groups_posts" " WHERE group_url='$get_group_url' ORDER BY post_id DESC LIMIT 5");
         

    function 
    custom_pagination($page$totalpage$link$show)  //$link = '&page=%s' 

        
    //show page 
    if($totalpage == 0

    return 
    'Error Fetching Data return = 0 of 0<br>'
    } else { 
        
    $nav_page '<div class="navpage"><span class="current">Page '.$page.' of '.$totalpage.': </span>'
        
    $limit_nav 3
        
    $start = ($page $limit_nav <= 0) ? $page $limit_nav
        
    $end $page $limit_nav $totalpage $totalpage $page $limit_nav
        if(
    $page $limit_nav >= $totalpage && $totalpage $limit_nav 2){ 
            
    $start $totalpage $limit_nav 2
        } 
        if(
    $start != 1){ //show first page 
            
    $nav_page .= '<span class="item"><a href="'.sprintf($link1).'"> [1] </a></span>'
        } 
        if(
    $start 2){ //add ... 
            
    $nav_page .= '<span class="current">...</span>'
        } 
        if(
    $page 5){ //add prev 
            
    $nav_page .= '<span class="item"><a href="'.sprintf($link$page-5).'">&laquo;</a></span>'
        } 
        for(
    $i $start$i <= $end$i++){ 
            if(
    $page == $i
                
    $nav_page .= '<span class="current">'.$i.'</span>'
            else 
                
    $nav_page .= '<span class="item"><a href="'.sprintf($link$i).'"> ['.$i.'] </a></span>'
        } 
        if(
    $page $totalpage){ //add next 
            
    $nav_page .= '<span class="item"><a href="'.sprintf($link$page+4).'">&raquo;</a></span>'
        } 
        if(
    $end $totalpage){ //add ... 
            
    $nav_page .= '<span class="current">...</span>'
        }     
        if(
    $end != $totalpage//show last page 
            
    $nav_page .= '<span class="item"><a href="'.sprintf($link$totalpage).'"> ['.$totalpage.'] </a></span>'
        
    $nav_page .= '</div>'
        return 
    $nav_page




    //using
    if(isset($_GET['page'])) {
        
    $page $_GET['page'];
    } else {
        
    $page 1;
    }

    $result $db->query("SELECT count(*) AS total FROM spud_groups_posts WHERE group_url='$get_group_url' ORDER BY post_body,post_id DESC");
    $rows $db->fetch_array($result);
    $show 10//Show 5 result per page
    $totalpage ceil($rows['total'] / $show); //Total page
    $start = ($page $show) - $show//Start result

    $fetch_updates $db->query("SELECT * FROM spud_groups_posts WHERE group_url='$get_group_url' ORDER BY post_id DESC LIMIT $start, $show") or die ('sss');
    while(
    $fetch_updates_array $db->fetch_array($fetch_updates)) {
    $post_id_row $fetch_updates_array['post_id'];
    $posted_by $fetch_updates_array['posted_by'];
    $posts_table $fetch_updates_array['post_body'];

    $escape_post_id_row $db->escape_string($post_id_row);
    echo(
    "<br>" "<a href=''> $posted_by </a>" "<br>" $posts_table);

                echo 
    "<br> 
    <form action='' method='POST'>
    <input type='text' name='comment_post' class='comment_post' placeholder='Write A Comment'>
    <input type='hidden' name='post_id_value' id='post_id_value' class='post_id_value' value='$post_id_row'>
    </form>
    "
    ;    








    $select_comments $db->query("SELECT * FROM " TABLE_PREFIX "groups_comments WHERE post_id='$escape_post_id_row'");









    $dbc mysql_connect("localhost""root""") or die(mysql_error());   
    mysql_select_db("spud_gaming") or die(mysql_error());  
    $start 0;  
    $limit 5;  
    if(isset(
    $_GET['start']))  
    {  
     
    $start = @mysql_real_escape_string(trim($_GET['start']));  
    }  
    if(
    is_numeric($start) === false)  
    {  
     
    $start 0;  
    }  
    $query "select * from spud_groups_comments WHERE post_id='$post_id_row' limit ".$start.", ".$limit;  
    $result = @mysql_query($query);  
    ?>  
    <div style="width: 20%;">  
    <?php  
    if($start > ($limit 2))  
    {  
     echo 
    '<a href="?start='.($start - ($limit 1)).'">&lt;&lt;previous</a>&nbsp;&nbsp;&nbsp;&nbsp;';  
    }  
    if(@
    mysql_num_rows($result) > ($limit 1))  
    {  
     echo 
    '<a href="?start='.($start + ($limit 1)).'" style="float: right;">next&gt;&gt;</a>';  
    }  
    echo 
    "</div>";           
    $i 0;  
    while(
    $row = @mysql_fetch_array($result))  
    {  
     if(
    $i == 5)  
     {  
      break;  
     }  
     
    $i ++;  
     echo 
    "<div>".$row['post_id'].") ".$row['post_body']."</div>";             
    }  












                echo 
    "<div class='update_comments'>";
                
            
                echo 
    "</div>";
                    echo 
    "
                    <br>
                    
                    __________________________<br>
                    
                    
                    "
    ;
                    

    }





    //Show pagination
    echo custom_pagination($page$totalpage'index.php?gname=first&page=%s'$show);






         if(
    $db->num_rows($fetch_clan_posts_query)){
                echo 
    '<ul id="records">';
                while(
    $fetch_clan_posts_array = @$db->fetch_array($fetch_clan_posts_query)){
                
            
                    
                }
               
            }

            
            
       
    //We have done everything we need to do we can now exit and not execute anything beyond this point

                    
                    



    ?>

  • #2
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?? Please

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,077
    Thanks
    2
    Thanked 320 Times in 312 Posts
    I don't think anyone understands the question. State or show what result you are getting now and what is wrong with it?

    edit: Let me rephrase my reply. No one wants to get involved with that code. It looks like it was hacked together from at least three different sources.

    If you want programmers to help you, your code must be organized enough so that someone who has never seen it before can look at it and deduce what it is supposed to be doing.
    Last edited by CFMaBiSmAd; 07-18-2014 at 02:52 AM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    New Coder
    Join Date
    Jul 2014
    Location
    Athens, Greece
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I agree with CFMaBiSmAd!

  • #5
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The pagination was as I have never created this before. And never mind I solved the problem


  •  

    Posting Permissions

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