|
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 |
xfactoria Smarty n00b
Joined: 25 Apr 2013 Posts: 3
|
Posted: Thu Apr 25, 2013 10:04 am Post subject: How to get data from data base {PHP, SMARTY} |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Apr 25, 2013 6:05 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Apr 30, 2013 11:32 pm Post subject: Re: How to get data from data base {PHP, SMARTY} |
|
|
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 |
|
xfactoria Smarty n00b
Joined: 25 Apr 2013 Posts: 3
|
Posted: Tue May 14, 2013 3:43 pm Post subject: |
|
|
Hi
Mohrt, i had just added those brackets like that 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 |
|
|
|
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
|