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

How to get data from data base {PHP, SMARTY}

 
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 -> Smarty Development
View previous topic :: View next topic  
Author Message
xfactoria
Smarty n00b


Joined: 25 Apr 2013
Posts: 3

PostPosted: Thu Apr 25, 2013 10:04 am    Post subject: How to get data from data base {PHP, SMARTY} Reply with quote

Hi everyone,
Am a new developer on PHP and Smarty, my question is about retrieving data from the reference that a user has put in the input text for a research.

This is the image actually:[url] http://imageshack.us/photo/my-images/594/recherchee.png/ [/url]


The .tpl code is :
Code:
<div id="tabs-3">
         <h2> Recherche par référence produit </h2>       
       
            <form method ="POST" action="kssearch.php">
               <p>
                 <label> Recherchez la référence d'un produit </label>
                 <input type ="text"  name="reference" value="{$ref}"/>
                <input type = "submit" value = "Rechercher" />
             </p>
           
           </form>
      </div>       


and the .php is :
Code:
public function recordReference(){
         
         $bd = db::getInstance()->getConnexion();
         $sql = "SELECT reference FROM ps_product WHERE reference = 'ref'";
         $resultat = $bd->query($sql);
         $ref = $resultat->fetchAll(PDO::FETCH_COLUMN,0);
         return $ref;
         
      }
      
         $smarty = new Smarty;
         $ref = $this->recordReference();
         $smarty->assign('result',$ref);
         $smarty->display('kssearch.tpl')
      }



Am having syntaxe error, could you suggest me something?

Thanks in advance.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Apr 25, 2013 6:05 pm    Post subject: Reply with quote

Quote:
public function recordReference(){

$bd = db::getInstance()->getConnexion();
$sql = "SELECT reference FROM ps_product WHERE reference = 'ref'";
$resultat = $bd->query($sql);
$ref = $resultat->fetchAll(PDO::FETCH_COLUMN,0);
return $ref;

}

$smarty = new Smarty;
$ref = $this->recordReference();
$smarty->assign('result',$ref);
$smarty->display('kssearch.tpl') <-- no semi-colon
} <-- what is this for?
Back to top
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Tue Apr 30, 2013 11:32 pm    Post subject: Re: How to get data from data base {PHP, SMARTY} Reply with quote

xfactoria wrote:
Hi everyone,
Am a new developer on PHP and Smarty, my question is about retrieving data from the reference that a user has put in the input text for a research.

How it is even SLIGHTLY relevant to Smarty, which is a template engine?

Quote:
This is the image actually:[url] http://imageshack.us/photo/my-images/594/recherchee.png/ [/url]


The .tpl code is :
Code:
<div id="tabs-3">
         <h2> Recherche par référence produit </h2>       
       
            <form method ="POST" action="kssearch.php">
               <p>
                 <label> Recherchez la référence d'un produit </label>
                 <input type ="text"  name="reference" value="{$ref}"/>
                <input type = "submit" value = "Rechercher" />
             </p>
           
           </form>
      </div>       


Now, either
<label for="id-reference">...</label><element id="id-reference ... />
or
<label><element ... />...</label>
What you did in your code is just. plain. wrong.

Quote:
and the .php is :
Code:
public function recordReference(){
         
         $bd = db::getInstance()->getConnexion();
         $sql = "SELECT reference FROM ps_product WHERE reference = 'ref'";
         $resultat = $bd->query($sql);
         $ref = $resultat->fetchAll(PDO::FETCH_COLUMN,0);
         return $ref;
         
      }
      
         $smarty = new Smarty;
         $ref = $this->recordReference();
         $smarty->assign('result',$ref);
         $smarty->display('kssearch.tpl')
      }



Am having syntaxe error, could you suggest me something?

Thanks in advance.

Your PHP code has obvous error that has been mentioned earlier.
Back to top
View user's profile Send private message
xfactoria
Smarty n00b


Joined: 25 Apr 2013
Posts: 3

PostPosted: Tue May 14, 2013 3:43 pm    Post subject: Reply with quote

Hi

Mohrt, i had just added those brackets like that Sad and i will put the semi-colon.

AnrDaemon, i am using Smarty template, may be i have a wrong syntaxe code but it is what am working with Prestashop.

So is there any way to write it right?

thanks for your advices.
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 -> Smarty Development 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