Smarty PHP Question
Question posted by: adamjblakey
(Member)
on
March 26th, 2008 01:57 PM
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.
Code: ( text )
// 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);
Can someone help me out?
Cheers,
Adam
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
March 26th, 2008 04:47 PM
# 2
|
Re: Smarty PHP Question
This link is pretty good, and it saves me writting out code!!
http://www.tonymarston.net/php-mysql/pagination.html
|
|
March 27th, 2008 12:48 AM
# 3
|
Re: Smarty PHP Question
Quote:
Originally Posted by harshmaul
|
I am afraid that Tony Marston article is about writing the pagination code yourself.
It does not address using the Smarty pagination plug-in.
Ronald
__________________
RTFM is an almost extinct art form.
|
|
March 27th, 2008 08:56 AM
# 4
|
Re: Smarty PHP Question
Quote:
Originally Posted by ronverdonk
I am afraid that Tony Marston article is about writing the pagination code yourself.
It does not address using the Smarty pagination plug-in.
Ronald
|
Yes this is what i was going to say,
I have changed the code a bit to try and get it to work but does not seem to function correctly.
Code: ( text )
// required connect SmartyPaginate::connect(); if(!isset($_GET['next'])){ $page = 1; } else { $page = $_GET['next']; } $max_results = 24; $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT * FROM users LIMIT $from, $max_results"); 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);
It just shows Items 1-24 out of 24 displayed and no other next or pages links but there is 60+ in the table.
|
|
March 27th, 2008 04:36 PM
# 5
|
Re: Smarty PHP Question
My suggestion is to go to the Smarty support people, because the problems almost certainly lies in the Smarty classes/functions.
Ronald
|
|
March 27th, 2008 11:40 PM
# 6
|
Re: Smarty PHP Question
I only started using paginate the other day I followed this
http://www.phpinsider.com/php/code/SmartyPaginate/
and worked first time..
|
|
March 27th, 2008 11:45 PM
# 7
|
Re: Smarty PHP Question
Quote:
Originally Posted by thefox149
|
thefox149: welcome to The Scripts. It is good to hear that you have found some way of pointer OP in the right direction of this Smarty problem. I was losing hope that we could solve this in this forum.
Thanks.
Ronald
__________________
RTFM is an almost extinct art form.
|
|
March 28th, 2008 08:42 AM
# 8
|
Re: Smarty PHP Question
Hi,
Thank you for your replies, i have tried directing this to specific smarty programmers but they don't seem to want to help.
As for the link this is what i followed and code is based on but i cannot get it to work correctly. The problem with that script is it uses an array and only briefly focuses on the MySQL solution.
Cheers,
Adam
|
|
March 28th, 2008 06:45 PM
# 9
|
Re: Smarty PHP Question
Code: ( text )
// required connect SmartyPaginate::connect(); // set items per page SmartyPaginate::setLimit(15); $sql = "Your Sql goes here"; // assign your db results to the template $smarty->assign('make', get_db_results($sql)); // assign {$paginate} var SmartyPaginate::assign($smarty); // display results // display results $smarty->display('your tpl'); function get_db_results($sql) { $_data = func_query($sql);//my own littel sql could easily use the mysql SmartyPaginate::setTotal(count($_data)); return array_slice($_data, SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit()); }
Please enclose your posted code in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use [code] tags in future.
MODERATOR
|
|
March 31st, 2008 08:38 AM
# 10
|
Re: Smarty PHP Question
Hi,
I have tried this but does not seem to work.
Code: ( text )
// required connect SmartyPaginate::connect(); // set items per page SmartyPaginate::setLimit(15); $sql = "SELECT * FROM users"; // assign your db results to the template $smarty->assign('array', get_db_results($sql)); // assign {$paginate} var SmartyPaginate::assign($smarty); function get_db_results($sql) { $_data = mysql_query($sql); //my own littel sql could easily use the mysql SmartyPaginate::setTotal(count($_data)); return array_slice($_data, SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit()); }
It is not displaying any results.
Not the answer you were looking for? Post your question . . .
183,939 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Latest Articles: Read & Comment
Top PHP Forum Contributors
|