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

smarty paginate : next resulte

 
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: Sun Jun 01, 2008 12:56 pm    Post subject: smarty paginate : next resulte Reply with quote

Hi,

I'm using smarty paginate to get an array of results from mysql. I then display a summary of each result in a table and one can click on "details" in order to display the full result of each line.

If I then want to display the next result, I must click on "back to list" and select the next result. However, I would like to add a link to the next result, without having to return to the list of summaries of results.

Here's what I do. In this code $ida is the identification number of each line of results.

.php file :


Code:
$requete = sprintf
("SELECT * FROM Actes, Bibliographie
WHERE id = idBiblio
%s
AND MotsClef LIKE %s
AND (Resume LIKE %s AND Resume LIKE %s)
AND NOT (Resume LIKE %s)
AND Nom_Auteur LIKE %s
AND Auteur LIKE %s
AND nompropre LIKE %s
AND localite LIKE %s
AND p_n LIKE %s
AND Contrat LIKE %s
AND annee BETWEEN %d AND %d ORDER BY annee",
$tx,
$sql->quote_smart($_SESSION['motcle']),
$sql->quote_smart($_SESSION['resume']),
$sql->quote_smart($_SESSION['ares']),
$sql->quote_smart($_SESSION['nres']),
$sql->quote_smart($_SESSION['nom_auteur']),
$sql->quote_smart($_SESSION['auteur']),
$sql->quote_smart($nompropre),
$sql->quote_smart($localite),
$sql->quote_smart($_SESSION['p_n']),
$sql->no_smart($_SESSION['contrat']),
$sql->quote_smart($_SESSION['anmin']),
$sql->quote_smart($_SESSION['anmax']));

}
}
$_SESSION['query'] = $requete ;
}


else {
$requete = $_SESSION['query'] ;
}


$demande = $sql->executerequete ($_SESSION['query']);
$value = $sql->findarray($demande);

$_SESSION['count'] = $sql->countlines ($demande);


$start = SmartyPaginate::getCurrentIndex();
$limit = SmartyPaginate::getLimit();
        $sql->quit();
        $smarty->assign('actes', array_slice($value, $start, $limit));
        SmartyPaginate::setTotal($_SESSION['count']);
        SmartyPaginate::assign($smarty);
        $smarty->assign('nombre',$_SESSION['nombre']);
        $smarty->assign('titre','les actes');
        $smarty->display('listeactes.tpl');
         SmartyPaginate::reset();




This gives an associative array. var_dump($value); gives (for a specific research with 290 results) :

Quote:
array(290) {
[0]=>
array(42) {
["ida"]=>
string(4) "1276"

blablablablabla

}
[1]=>
array(42) {
["ida"]=>
string(4) "1253"

blablablablabla

}
[2]=>
array(42) {
["ida"]=>
string(4) "1529"

blabla
}

etc etc etc...



Then the listeactes.tpl :

Code:
   <div id="txuni">
   <ul class="enumeras">
   {section name=i loop=$actes}
      <li>
      <span id="vi"><strong>{$actes[i].annee}</strong></span>
      {if $lst == "o"}<span id="ctt">{$actes[i].Contrat}</span>{/if}
      <span id="vib"><strong>{$actes[i].Nom_Auteur} {if $actes[i].Co_auteur !=''} et {$actes[i].Co_auteur} {/if}: {$actes[i].titre|truncate:50:"..."}</strong></span><br />
      <span id="vr">{$actes[i].MotsClef|truncate:120:"..."}</span>
      
<a class="llettre" href="ficheacte.php?ida={$actes[i].ida|escape:"url"}">Full result</a>

      </li>
   {/section}
   </ul>
   </div>


If you click on the link Full result in the end of the code, you get the to see
ficheacte.php?ida={$actes[i].ida|escape:"url}

fichacte.php contains a quite simple mysql request :

Code:
$requete = "SELECT *  FROM Actes, Bibliographie WHERE Bibliographie.id = idBiblio AND ida='{$_GET['ida']}' ";


The result of this is displayed (this is the full result). At the end of the page, you get some links : history.back, modify the file, or print .pdf of this file.


Code:
<p class="vx">
<span id="vy"><a class="fiche" href="javascript:history.back()">retour la liste</a></span>

<span id="vb"><a class="fiche" href="palactes.php?mode={$smarty.const.MODE_MODIF|escape:"url"}&ida={$fiche[i].ida|escape:"url"}">modify this file</a></span>

{if $fiche[i].Texte !=""}
<span id="boa"><a class="fiche" href="pdfacte.php?ida={$fiche[i].ida|escape:"url"}">.pdf</a></span>
{/if}
</p>


Here, I would like to add a link to "next result".
Next result is :

ficheacte.php?ida= THENEXT$actes[i].ida|escape:"url"

How do I get this next ida ??? It's already in the array I got from mysql at the first request, but I don't know how to extract only that ida here...

Does anyone have an idea ???

MANY MANY THANKS
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Sun Jun 01, 2008 4:50 pm    Post subject: Reply with quote

You might use a separate pagination list on the product page, with just three items: prev, current, and next item. That way when you go next, next, next, you always have the correct pagination.
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: Sun Jun 01, 2008 5:56 pm    Post subject: Reply with quote

Hello,

I thought of that but I don't see how that's possible.

Maybe my explanations were not clear (or too long). Here's what I do : I first get all the results resulting from a specific request from mysql and display only summeries of those in a table. I use smarty pagination for that, since in some cases, that can lead to almost 2000 results....

If the user want to see the entire result of one sepecific entry, he must select one line from the list of summeries. I then retrieve the entire line from mysql and display only that line. I do not use smarty pagination here since there always is only one result. Do I understand you correctly ? Is this were you propose that I retreive all the results again and use smarty paginate with just three item ?

The other work-around I had found was using

Code:
{$actes[i.index_next].ida}


put the result of that in $_GET and create a mysql query where id is {$actes[i.index_next].ida}.

But this does not work for the last result on a give page of summeries (using smarty paginate), since that does not show the first result of the next page....
[/b]
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Sun Jun 01, 2008 6:01 pm    Post subject: Reply with quote

on the page that displays one result, use smarty paginate to get three results from the summary set: prev, current, and next item. does that make sense?
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: Sun Jun 01, 2008 6:35 pm    Post subject: Reply with quote

I guess it makes sense.
I'll give it a try !
Many thanks - I'll post here how it works out.
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