Smarty PHP Question

Discussion in 'PHP' started by adamjblakey, Mar 26, 2008.

  1. #1
    Hi,

    I am trying to implement pagination into my site but am having a few problems.

    This is my code, but when i load the page all the results show and when i click to the next page 2 it shows the same results. It does not seem to be splitting the results between 2 pages.

    
    // required connect
        SmartyPaginate::connect();
        // set items per page
        SmartyPaginate::setLimit(20);
    
       $sql = mysql_query("select * from users");   
       while($row = mysql_fetch_array($sql)){
       $array[] = $row;
       }
       
        // now we get the total number of records from the table
            $sql = mysql_query("SELECT FOUND_ROWS() as total");
            $row = mysql_fetch_array($sql, MYSQL_ASSOC);
           
            SmartyPaginate::setTotal($row['total']);
       
       $smarty->assign("array", $array);
       
        // assign {$paginate} var
        SmartyPaginate::assign($smarty);
       
       // Assign New Members
       $cols_per_row = 4;
       $smarty->assign('cols_per_row', $cols_per_row); 
    
    PHP:

    Can someone help me out?
    Cheers,
    Adam
     
    adamjblakey, Mar 26, 2008 IP
  2. lawrenz

    lawrenz Peon

    Messages:
    246
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    when you click the next page try to use limit and offset

    or first is count all the records and then add a limit.. example:

    $limit = 10;

    if(!isset($paging_page))
    {
    $paging_page = 1;
    }
    else
    {
    $paging_page = $paging_page;
    }
    $sql = "select count(*) as count_all from users";
    if(!$q = mysql_query($sql))
    {
    echo mysql_error();
    }
    elseif(mysql_num_rows($Q) == 0)
    {
    echo "No result found";
    }
    else
    {
    $r = $mysql_fetch_assoc($q);
    $show_count = $r['count_all'];

    $numPages = ceil($show/ $limit);
    $offset = ($paging_page - 1) * $limit;
    /* limit output*/
    $sql = "select * from users limit $offset, $limit";
    /*... and so on */

    }
     
    lawrenz, Mar 26, 2008 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Thank you for your reply, but i don't know how to get this working within smarty and that is what the site is in.
     
    adamjblakey, Mar 26, 2008 IP