|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
thiebo Smarty Pro
Joined: 16 Jan 2005 Posts: 144 Location: Paris
|
Posted: Mon Mar 28, 2005 7:59 am Post subject: paginate no error messages |
|
|
Hello,
Trying to get SmartyPaginate to work, here's what I do :
[php:1:177c5c9006]<?php
function get_db_results ()
{
$key = $_POST['key'];
$blah = $_POST['blah'];
$boo = $_POST['boo'];
$connexion = connexion (NOM, PASSE, BASE, SERVEUR);
$query = "SELECT * FROM table, tabletwo
WHERE table.id = idtabletwo
AND word LIKE '%$key%'
AND blah LIKE '%$blah%'
AND boo LIKE '%$boo%'
ORDER BY year;
$actes = sql_query($query);
return $actes;
}
?>[/php:1:177c5c9006]
and :
[php:1:177c5c9006]<?php
if (isSet($_POST['find']))
{
// required connect
SmartyPaginate::connect();
// set items per page
SmartyPaginate::setLimit(7);
$start = SmartyPaginate::getCurrentIndex();
$limit = SmartyPaginate::getLimit();
$data = get_db_results ();
$smarty->assign('actes', array_slice($data, $start, $limit));
SmartyPaginate::setTotal(count_results());
SmartyPaginate::assign($smarty);
// display results
$smarty->display('listeactes.tpl');
}
?>[/php:1:177c5c9006]
where count_results() is a simple mysql_num_rows.
(I know I could have used SQL_CALC_FOUND_ROWS)...
this returns nice results when I get it going, counts the results correctly, provides a nice array (did a print_r(get_db_results())
but when I click on the link to the 7 next results, I get a white page, no error message and nothing in view-source.
The url does change from http://localhost/simple.php to http://localhost/simple.php?next=8
but that's about it.
I was hoping maybe to resolve this by using the SmartyPaginate::getUrl() function, but since I don't get any error messages, I'm not certain whether this would be a solution.
I don't see what I'm doing wrong here.... |
|
Back to top |
|
thiebo Smarty Pro
Joined: 16 Jan 2005 Posts: 144 Location: Paris
|
Posted: Mon Mar 28, 2005 8:45 am Post subject: |
|
|
when integrating SmartyPaginate::getUrl, I think the problem comes from /?next=8 in the url not being identified....
this is what I now do :
[php:1:4f3053c10b]<?php
if (isSet($_POST['find']))
{
SmartyPaginate::connect();
SmartyPaginate::setLimit(7);
$motcle = $_POST['motcle'];
$connexion = connexion (NOM, PASSE, BASE, SERVEUR);
$query = sprintf ("SELECT * FROM table, tabletwo
WHERE table.id = idtabletwo
AND key LIKE '%%%1\$s%%' ", $key);
$data = sql_query ($query);
SmartyPaginate::setTotal(count_results());
SmartyPaginate::setUrl(sprintf("http://localhost/simple.php/?key=%s", $key));
$start = SmartyPaginate::getCurrentIndex();
$limit = SmartyPaginate::getLimit();
$smarty->assign('actes',array_slice ($data, $start, $limit));
SmartyPaginate::assign($smarty);
$smarty->display('listeactes.tpl');
}
?>[/php:1:4f3053c10b]
the first set of results is fine and the url : http://localhost/simple.php
click on the second set of resuts, get a white page, no error message and the url : http://localhost/simple.php/?key=don&next=8
"don" is what I had filled out for key, that's correct...
maybe the url isn't found, I don't understand... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 28, 2005 2:54 pm Post subject: |
|
|
What does the template look like? this should work OK. maybe debug what data you are getting back from your SQL query. On a side note, it might be more efficient to select only the records you want from the db, instead of selecting everything and then slicing out the pagination content afterwards. |
|
Back to top |
|
thiebo Smarty Pro
Joined: 16 Jan 2005 Posts: 144 Location: Paris
|
Posted: Mon Mar 28, 2005 4:13 pm Post subject: |
|
|
Hi Monte,
Thanks for answering again.
When I enter a request with a keyword giving 20 results, the array I get from mysql is the 20 results array that looks like this :
Quote: | Array
(
[0] => Array
(
[0] => 108
[ida] => 108
[1] => 1
[idBiblio] => 1
[2] => 14
[numero_acte] => 14
[3] =>
[compl_biblio] =>
[4] => 1217
[annee] => 1217
)
[1] => Array
(
[0] => 116
[ida] => 116
etc etc. ))
|
By the way, the function sql_query that I use looks like this (I use this for the entire site and it gives good results):
[php:1:1597089d21]<?php
function sql_query($query)
{
$result = mysql_query($query);
$return_array = array();
while ($row = mysql_fetch_array($result)){
array_push($return_array, $row);
}
mysql_free_result($resultat);
return $return_array;
?>[/php:1:1597089d21]}
This is what I do in my template :
Code: |
{include file="header.tpl"}
<br />
{$paginate.first}-{$paginate.last} sur {$paginate.total}
<br />
{section name=i loop=$actes}
<td width=2%><b>{$smarty.section.i.rownum}</b></td>
<td width=4%>{$actes[i].annee}</td>
<td width=10%>{$actes[i].Nom_Auteur}</td>
<td width=30%>{$actes[i].titre}</td>
{/section}
{paginate_first} {paginate_prev} {paginate_middle format="page" page_limit="10"} {paginate_next} {paginate_last}
|
The first results are fine ! The URL is this :
http://localhost/fonstheobaldi/privmed/actesimple.php
when I click on the link to the next set of results, I get a white page, no error messages and only a new URL :
http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
this URL, theoretically speaking, should be fine, but something goes wrong. Considering how it functions, I don't think that SmartyPaginate goes the mysql query a second time.
Could the problem be that when I submit the query from the form, the code of that form contains this :
Quote: | <input type = hidden name='find' value='find'> |
Then off course, if SmartyPaginate goes over the code containing the pagination, this statement is not met :
[php:1:1597089d21]<?php
if (isSet($_POST['find']))
?>[/php:1:1597089d21]
I've tried to do without the if (isset), but the result isn't any better, because when I then click on the next 7 results (out of 20), I get the entirety of the database in a nice array, mysql error messages and a template that seems to ignore my CSS stylesheet...
Many thanks,
Regards,
?>[/php] |
|
Back to top |
|
thiebo Smarty Pro
Joined: 16 Jan 2005 Posts: 144 Location: Paris
|
Posted: Mon Mar 28, 2005 4:29 pm Post subject: |
|
|
Sorry,
I'm not being precise enough. When I click on the second range of results, I do get error messages :
and :
This seems hardly surprising, since all the data was retrieved from mysql, and the script does not go over the form again. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 28, 2005 5:11 pm Post subject: |
|
|
It looks like you are trying to use $_POST on the second pagination query, which will be empty. You need to store the posted info for the next query. Something like:
[php:1:d4a649be16]session_start();
if(!empty($_POST))
$_SESSION['POST'] = $_POST;[/php:1:d4a649be16]
Then use $_SESSION['POST'] instead of $_POST in the rest of your logic. |
|
Back to top |
|
thiebo Smarty Pro
Joined: 16 Jan 2005 Posts: 144 Location: Paris
|
Posted: Mon Mar 28, 2005 7:14 pm Post subject: |
|
|
Hi again,
Thanks for this. This is what I now do :
[php:1:d359b3a9dc]<?php
session_start ();
require ('path.php');
require ('mysql.php');
require('SmartyPaginate.class.php');
$smarty = new Smarty_smartysite;
if(!empty($_POST)){
$_SESSION['POST'] = $_POST;
}
if (isSet($_POST['find']))
{
function count_results (){
bla bla
}
SmartyPaginate::connect();
SmartyPaginate::setLimit(7);
$motcle = $_SESSION['POST']['motcle'];
$connexion = connexion (NOM, PASSE, BASE, SERVEUR);
$query = sprintf ("SELECT * FROM Actes, Bibliographie
WHERE Bibliographie.id = idBiblio
AND MotsClef LIKE '%%%1\$s%%' ", $motcle);
$data = sql_query ($query);
SmartyPaginate::setTotal(count_results());
SmartyPaginate::setUrl(sprintf("http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=%s", $motcle));
$start = SmartyPaginate::getCurrentIndex();
$limit = SmartyPaginate::getLimit();
$smarty->assign('actes',array_slice ($data, $start, $limit));
SmartyPaginate::assign($smarty);}
$smarty->display('listeactes.tpl');
?>[/php:1:d359b3a9dc]
Entering a query giving 20 results, are correctly counted, first page looks fine, clicking on second page, gives me a white page with only my navigation bar, and this url :
http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
trying to get back to the homepage, the url becomes :
http://localhost/fonstheobaldi/privmed/actesimple.php/accueil.php
as if it's trying to reach both pages....
sorry to be a pain on this one... I really need the pagination, and I really appreciate the smarty logic, so I don't want to give up.
Many thanks again,
Thiebo |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 28, 2005 7:34 pm Post subject: |
|
|
Open the smarty debugging console ($smarty->debugging = true) and see if the data you expect is getting assigned to the template. Did you get the PHP errors figured out? |
|
Back to top |
|
thiebo Smarty Pro
Joined: 16 Jan 2005 Posts: 144 Location: Paris
|
Posted: Mon Mar 28, 2005 7:45 pm Post subject: |
|
|
well well well,
when I put debugging to true, I get some results !
on the first set of results (the ones that look fine) :
and when I click on the next set of results, here's what I get :
Quote: | [client 127.0.0.1] PHP Notice: Undefined index: titre in /var/www/html/smarty/templates_c/%%08^083^083EFAB2%%entete.tpl.php on line 6, referer: http://localhost/fonstheobaldi/privmed/actesimple.php
[client 127.0.0.1] PHP Notice: Undefined index: paginate in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 26, referer: http://localhost/fonstheobaldi/privmed/actesimple.php
[client 127.0.0.1] PHP Notice: Undefined index: paginate in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 27, referer: http://localhost/fonstheobaldi/privmed/actesimple.php
[client 127.0.0.1] PHP Notice: Undefined index: paginate in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 28, referer: http://localhost/fonstheobaldi/privmed/actesimple.php
[client 127.0.0.1] PHP Notice: Undefined index: titre in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 33, referer: http://localhost/fonstheobaldi/privmed/actesimple.php
[client 127.0.0.1] PHP Notice: Undefined index: actes in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 53, referer: http://localhost/fonstheobaldi/privmed/actesimple.php
[client 127.0.0.1] PHP Notice: Undefined variable: _ret in /usr/local/lib/php/Smarty/plugins/function.paginate_middle.php on line 108, referer: http://localhost/fonstheobaldi/privmed/actesimple.php
[client 127.0.0.1] PHP Notice: Undefined variable: _display_pages in /usr/local/lib/php/Smarty/plugins/function.paginate_middle.php on line 112, referer: http://localhost/fonstheobaldi/privmed/actesimple.php
[client 127.0.0.1] PHP Notice: Undefined index: titre in /var/www/html/smarty/templates_c/%%08^083^083EFAB2%%entete.tpl.php on line 6, referer: http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
[client 127.0.0.1] PHP Notice: Undefined index: paginate in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 26, referer: http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
[client 127.0.0.1] PHP Notice: Undefined index: paginate in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 27, referer: http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
[client 127.0.0.1] PHP Notice: Undefined index: paginate in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 28, referer: http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
[client 127.0.0.1] PHP Notice: Undefined index: titre in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 33, referer: http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
[client 127.0.0.1] PHP Notice: Undefined index: actes in /var/www/html/smarty/templates_c/%%47^472^472A8441%%listeactes.tpl.php on line 53, referer: http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
[client 127.0.0.1] PHP Notice: Undefined variable: _ret in /usr/local/lib/php/Smarty/plugins/function.paginate_middle.php on line 108, referer: http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
[client 127.0.0.1] PHP Notice: Undefined variable: _display_pages in /usr/local/lib/php/Smarty/plugins/function.paginate_middle.php on line 112, referer: http://localhost/fonstheobaldi/privmed/actesimple.php/?motcle=don&next=8
|
That's quit a bunch of errors isn't it ?
I was actually hoping that the $_SESSION['POST'] would resolve the php errors... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 28, 2005 7:54 pm Post subject: |
|
|
Actually those are just warnings, you're error reporting is set way high. You should try using the default:
error_reporting(E_ALL ^ E_NOTICE); |
|
Back to top |
|
thiebo Smarty Pro
Joined: 16 Jan 2005 Posts: 144 Location: Paris
|
Posted: Mon Mar 28, 2005 8:09 pm Post subject: |
|
|
yes, but error_reporting(E_ALL ^ E_NOTICE);
puts it to a lower level of reporting. I'm still developping on my own computer, once I publish my site on a server, I will not have much choise of the level of errors. For the time being, I'm hoping to make this the best I can...
this really is strange : the exemple you give in the README document is clear and works really neat, but for some reason I just don't understand, I find difficulties changing $_data = range (1,100) to $_data = mysql_query_results(). It seems dead simple in principle, but I've again spent a long weekend trying to paginate.... (happy me, my wife is with my in-laws).
Still the range of data I get from my mysql_query is an array just as many other arrays of mysql-results in my website.
you don't happen to see what I'm doing wrong ? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Mar 28, 2005 10:02 pm Post subject: |
|
|
I can't see from what you posted, I guess you'll have to compare line by line until it becomes apparent what isn't right. |
|
Back to top |
|
thiebo Smarty Pro
Joined: 16 Jan 2005 Posts: 144 Location: Paris
|
Posted: Mon Mar 28, 2005 10:11 pm Post subject: |
|
|
I guess...
many thanks for your time and help,
kind regards, |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|