473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Smarty PHP Question

133 100+
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.

[PHP]
// 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
Mar 26 '08 #1
9 2867
harshmaul
490 Expert 256MB
This link is pretty good, and it saves me writting out code!!

http://www.tonymarston.net/php-mysql/pagination.html
Mar 26 '08 #2
ronverdonk
4,258 Expert 4TB
This link is pretty good, and it saves me writting out code!!

http://www.tonymarston.net/php-mysql/pagination.html
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
Mar 27 '08 #3
adamjblakey
133 100+
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.

[PHP] // 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);[/PHP]

It just shows Items 1-24 out of 24 displayed and no other next or pages links but there is 60+ in the table.
Mar 27 '08 #4
ronverdonk
4,258 Expert 4TB
My suggestion is to go to the Smarty support people, because the problems almost certainly lies in the Smarty classes/functions.

Ronald
Mar 27 '08 #5
I only started using paginate the other day I followed this

http://www.phpinsider.com/php/code/SmartyPaginate/

and worked first time..
Mar 27 '08 #6
ronverdonk
4,258 Expert 4TB
I only started using paginate the other day I followed this
http://www.phpinsider.com/php/code/SmartyPaginate/
and worked first time..
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
Mar 27 '08 #7
adamjblakey
133 100+
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
Mar 28 '08 #8
[php]// 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());
}[/php]

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
Mar 28 '08 #9
adamjblakey
133 100+
Hi,

I have tried this but does not seem to work.

[PHP] // 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());

}[/PHP]

It is not displaying any results.
Mar 31 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Brian | last post by:
I have an application that uses an array of values as a "lookup" table and smarty as a template engine. $lookup = "label"; $lookup = "label2"; $lookup = "label"; $lookup = "label2"; In my...
1
by: Richard | last post by:
I need help. I have a smarty based program that I am modifying. I have a smarty template file that consists of smarty and HTML. I need to integrate some PHP database calls into it. My problem...
1
by: DJ Majestik | last post by:
OK, I am new to the whole PEAR/Smarty templating thing. I am trying to setup my directory structure correctly. If someone could weigh in and see if I have this setup "right", I would appreciate it....
2
by: M | last post by:
Hi Folks, I am trying to install Smarty using PHP 5 on a Windows XP PC using IIS v6 The following PHP File: <!doctype html public "-//W3C//DTD HTML 4.0 //EN"> <html> <head>
0
by: Matt | last post by:
geez, i've done this a million times, you'd think i could get it right. uploading to production server for a new site, and part of the head.inc that starts everything up looks like this: echo...
2
by: Freebird | last post by:
Hello you all, =] I've a smarty var, like this: {$var} that is equal to: ttttttttttttt|zzzzzzzzzzzz It can be any size, the important is that they are separated by the '|' How do I...
0
by: Conrad | last post by:
Hi, I'm very new to Smarty Template Engine and I'm using PHP 5.0.4 on the Windows XP Professional platform and I have the following question: When I change the 7th line of the script to use a...
2
by: Gene | last post by:
i'm newcomer in using smarty and i have problem like this: i want to have one template file (e.g. index.tpl) in this file section which use variable {$content}. and two files *.php which are using...
7
by: diane100 | last post by:
Hi I am new to PHP and Smarty (I know only very basic things) and I need help with a warning message I get when I call a page in a browser. I purchased some software from a company who are no...
1
by: empiresolutions | last post by:
i have what may be a very simple question for someone who has worked with X-Cart or Smarty. I am adding a rollover image next to the category names in the main navigation. The following is my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.