Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

display the same sql request with 2 different LIMIT

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
allhambra
Smarty n00b


Joined: 04 Jun 2014
Posts: 2

PostPosted: Wed Jun 04, 2014 2:14 pm    Post subject: display the same sql request with 2 different LIMIT Reply with quote

hi everyone,
I'm just beginning with smarty so any help or advise would be appreciated.

I've got to display 2 sql requests like this :
- services
3 displays on index.tpl
5 displays on footer.tpl

- actualités
4 displays on index.tpl
5 displays on footer.tpl

I've attempted to make 2 differents sql requests :
- $services with LIMIT 0,3 (index)
- $servs with LIMIT 0,5 (footer)
-$actualites with LIMIT 0,4 (index)
-$actu with LIMIT 0,5 (footer)
but it doesn't seem to work and return a blank page.

So i've found array_slice and thought i could be a good way to make it, but i don't know how to use it.
Should i use it in the php page or can i put it on tpl page ?
index.php
Code:
$services = $connexion->prepare("SELECT * FROM services");
$services->execute();

$list_services = array();
$i = 0;
while($data = $services->fetch()){
$output = array_slice($services, 3);     
$output = array_slice($services, 0, 3);   

   $list_services[$i]['id'] = $data['id'];
    $list_services[$i]['nom'] = $data['nom'];
    $list_services[$i]['description'] = $data['description'];
    $list_services[$i]['image'] = $data['image'];
   $list_services[$i]['prix'] = $data['prix'];

    $i++;
}

$actualites = $connexion->prepare("SELECT * FROM actualites LIMIT 0,4");
$actualites->execute();

$list_actualites = array();
$i = 0;
while($data = $actualites->fetch()){
   $list_actualites[$i]['id'] = $data['id'];
    $list_actualites[$i]['auteur'] = $data['auteur'];
    $list_actualites[$i]['titre'] = $data['titre'];
    $list_actualites[$i]['date'] = $data['date'];
   $list_actualites[$i]['texte_news'] = $data['texte_news'];

    $i++;
}


index.tpl
Code:
{foreach from=$list_services item=services}
                  <div class="grid_4">
            <figure class="image_box">
                      <div class="for_ie"></div>
                      <div class="image"><img src="uploads/services/{$services.image}" alt="" width="194"></div> </figure>
            <div class="thumb">
                      <h2>{$services.nom}</h2>
                      <p>{$services.description|truncate:400}
                     </p>
                      <a href="service.php?id={$services.id}" class="link_1">Voir le service</a> </div>
          </div>
         
            {/foreach}

  {foreach from=$list_actualites item=actualites}

          <div class="grid_3">
            <div class="thumb_1">
              <figure class="number">
                <h6>{$actualites.date|date_format:'%d<br />%m<br />%Y'}</h6>
              </figure>
              <div class="img1"><a class="link_3" href="#">{$actualites.titre}</a></div>
              <p class="auteur">Publié par {$actualites.auteur}</p>
              {$actualites.texte_news}
            </div>
          </div>
         {/foreach}



Thanks
Back to top
View user's profile Send private message
allhambra
Smarty n00b


Joined: 04 Jun 2014
Posts: 2

PostPosted: Thu Jun 05, 2014 11:00 am    Post subject: it's coming on Reply with quote

i've change the php file like this :
Code:
$services = $connexion->prepare("SELECT * FROM services");
$services->execute();

$list_services = array();
$i = 0;
while($data = $services->fetch()){
   
   //$input = array("a", "b", "c", "d", "e");
   $list_services[$i]['id'] = $data['id'];
    $list_services[$i]['nom'] = $data['nom'];
    $list_services[$i]['description'] = $data['description'];
    $list_services[$i]['image'] = $data['image'];
   $list_services[$i]['prix'] = $data['prix'];

    $i++;
}
$services3 = array_slice($list_services, 0, 5);      // 5 first elements
$servs = array_slice($list_services, 0, 3);   // returns 3 first elements
$smarty->assign('servs', $servs);
$smarty->assign('services3', $services3);



In the debug console i've got :

Code:
$services3   Smarty_Variable Object (3)
->value = Array (4)
  0 => Array (5)
    id => "3"
    nom => "Site administrable basique"
    description => "<h1>Cette offre comprend</h1> <ul>..."
    image => "site-administrable.png"
    prix => "400"
  1 => Array (5)
    id => "4"
    nom => "Site administrable classique"
    description => "<h1>Cette offre comprend</h1> <ul>..."
    image => "site-administrable.png"
    prix => "800"
  2 => Array (5)
    id => "5"
    nom => "Site administrable premium"
    description => "<h1>Cette offre comprend</h1> <ul>..."
    image => "site-administrable.png"
    prix => "1200"
  3 => Array (5)
    id => "6"
    nom => "Template ID Nature"
    description => "<p>Les template de site web Responsiv..."
    image => "idnature.png"
    prix => "50"
->nocache = false
->scope = "file:index.tpl"
$servs   Smarty_Variable Object (3)
->value = Array (3)
  0 => Array (5)
    id => "3"
    nom => "Site administrable basique"
    description => "<h1>Cette offre comprend</h1> <ul>..."
    image => "site-administrable.png"
    prix => "400"
  1 => Array (5)
    id => "4"
    nom => "Site administrable classique"
    description => "<h1>Cette offre comprend</h1> <ul>..."
    image => "site-administrable.png"
    prix => "800"
  2 => Array (5)
    id => "5"
    nom => "Site administrable premium"
    description => "<h1>Cette offre comprend</h1> <ul>..."
    image => "site-administrable.png"
    prix => "1200"
->nocache = false
->scope = "file:index.tpl"


but in the tpl file
Code:
 {foreach from=$servs item=servs}
                  <div class="grid_4">
            <figure class="image_box">
                      <div class="for_ie"></div>
                      <div class="image"><img src="uploads/services/{$servs.image}" alt="" width="194"></div> </figure>
            <div class="thumb">
                      <h2>{$servs.nom}</h2>
                      <p align="justify">{$servs.description|truncate:400}
                     </p>
                      <a href="service.php?id={$sers.id}" class="link_1">Voir le service</a> </div>
          </div>
         
            {/foreach}


return a blank page Sad.
Any ideas ?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General 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