Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

SmartyPaginate mysql_fetch_array error

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
thiebo
Smarty Pro


Joined: 16 Jan 2005
Posts: 144
Location: Paris

PostPosted: Thu Feb 03, 2005 7:41 am    Post subject: SmartyPaginate mysql_fetch_array error Reply with quote

Hello again.

Sorry, I still have difficulties getting SmartyPaginate to work and although I get an nice error message, I don't know what to do with it.

Here's what I do :

[php:1:01b5fa2956]<?php
session_start();
require ('/usr/local/lib/php/Includes/smartysite/setup.php');
require ('mysql.php');
require ('fonctions.php');
require ('SmartyPaginate.class.php');
$smarty = new Smarty_smartysite;

$smarty->assign ('titre','rechercher des actes');
SmartyPaginate::connect();
SmartyPaginate::setLimit(7);

$smarty->assign('aactes', get_db_results());
SmartyPaginate::assign($smarty);
$smarty->display('actes.tpl');
?>
?>[/php:1:01b5fa2956]

In order to get the correct array data from mysql, I use 2 functions :

[php:1:01b5fa2956]<?php
function sql_query($requete)
{
$resultat = mysql_query($requete);
$return_array = array();
while ($row = mysql_fetch_array($resultat)){
array_push($return_array, $row);
}
mysql_free_result($resultat);
return $return_array;
}
?>[/php:1:01b5fa2956]

AND of course :

[php:1:01b5fa2956]<?php
function get_db_results()
{
$motcle = $_POST['motcle'];
$anmin = $_POST['anmin'];

$connexion = connexion (NOM, PASSE, BASE, SERVEUR);
$requete = "SELECT * FROM Actes, Bibliographie
WHERE Bibliographie.id = idBiblio
AND MotsClef LIKE '%$motcle%'
AND annee BETWEEN $anmin AND $anmax ORDER BY annee
LIMIT ". SmartyPaginate::getCurrentIndex() . ", ". SmartyPaginate::getLimit();
$_data = sql_query($requete);
SmartyPaginate::setTotal(50);
return $_data;
}
?>[/php:1:01b5fa2956]


The pieces of code above get the array from Mysql correctly and dispose it in my webbrower, where I get to see the 7 first results, and the links to the next page , previous page ect, within the limit of 50 (which is the limit I set in function get_db_results). However, when I click to the 7 following results, I don't get the information collected from mysql.

the query is correctly memorised though, since when I go back to the form where I enter the query, and ask for that, I get to see the results 7 to 14 !!!

the error message is that :

Quote:
[client 127.0.0.1] PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/smartysite/mysql.php on line 61, referer: http://localhost/smartysite/becherche.php?next=1
[client 127.0.0.1] PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /var/www/html/smartysite/mysql.php on line 64, referer: http://localhost/smartysite/becherche.php?next=1


this does surprise me a bit because I use this mysql-function (showed above) in other requests too.

Does anybody see what I'm doing wrong ? Does anybody have a full working exemple with mysql and SmartyPaginate ?

I know I have already asked some questions on SmartyPaginate and that did help me out a lot. I must be close to the solution, but I'm affraid I do need some help.

Thiebo
Back to top
View user's profile Send private message Visit poster's website
thiebo
Smarty Pro


Joined: 16 Jan 2005
Posts: 144
Location: Paris

PostPosted: Thu Feb 03, 2005 8:09 am    Post subject: Reply with quote

I forgot to add that when I get my first page of results which is fine and click to the second page of result, the mysql_error =

Quote:
You have an error in your SQL syntax near 'AND ORDER BY annee LIMIT 1, 7' at line 8


Which seems logical since I'm asking for results 8 to 14....
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Thu Feb 03, 2005 3:21 pm    Post subject: Reply with quote

"AND ORDER BY" is a syntax error. Your $anmax variable must be empty the second time around, causing this error.
Back to top
View user's profile Send private message Visit poster's website
thiebo
Smarty Pro


Joined: 16 Jan 2005
Posts: 144
Location: Paris

PostPosted: Thu Feb 03, 2005 3:53 pm    Post subject: Reply with quote

Thanks again for answering. I'll alter that tonight. It's funny though because the anmax is has a default value in the form, e.g. if you don't fill anything out, you're sure it has a value, whereas the 6 or 7 other criteria I use (the code I sent is a summery) are often empty.
Thanks again.
Regards,
Thiebo
Back to top
View user's profile Send private message Visit poster's website
thiebo
Smarty Pro


Joined: 16 Jan 2005
Posts: 144
Location: Paris

PostPosted: Thu Feb 03, 2005 7:59 pm    Post subject: Reply with quote

Hi again !

It's all right now, thing works great and it's quit a relief, since I did all the rest of my website with smarty, I didn't want to make an exception for pagination !

One of the errors I made was this script :

[php:1:b963843f60]<?php

if(empty($_POST))
{
$smarty->display('recherche.tpl');
}

if(isset($_POST['multi']))
{

$smarty->assign('aactes', get_db_results());
SmartyPaginate::assign($smarty);
$smarty->display('actes.tpl');
}

?>[/php:1:b963843f60]


by doing that, the pagination came back to the form (recherche.tpl) when going from the first 7 results to the next 7 results... pretty frustrating. The solution was to isolate the pagination in one script only.

Really cool stuff, many many thanks, your help also showed me how to make and analyse error messages (you must have undertood, I'm a real real newby).

Thanks again -
Kind regards,

Thiebo
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP