|
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 |
sodenk Smarty n00b
Joined: 22 Feb 2016 Posts: 1
|
Posted: Tue Feb 23, 2016 12:20 am Post subject: SQL queries between pages |
|
|
I'm trying to display the results from a SQL query on my results.tpl page.
I've been banging my head against this all day, can someone look at my code and point me in the right direction? Or am I better off trying to do some sort of javascript/ajax to get this working?
For context, I'm using booked scheduler. In order for me to get the template working right - I have to link to results.php which goes to resultspage.php which goes to results.tpl. But I can't put results.php in the smarty->display.
Basically here's the flow of what I'm trying to do. There are a lot more queries/results I need to add but I'm just trying to get the basics working...
scan.tpl user enters number -> handler.php queries database -> results.tpl display results
Any help is much appreciated!
scan.tpl
Code: | {include file='globalheader.tpl'}
<div id="xx">
<form action="handler.php" method="post" >
<input type="number" name="barcode" value="1" />
<input type="submit" value="Submit" name="submit" />
</form >
</div>
{include file='globalfooter.tpl'} |
handler.php
Code: | require_once('c:/xxx/Smarty/Smarty.class.php');
$smarty = new Smarty();
$host = "xxx";
$user = "xxx";
$password = "xxx";
$database_name = "xxx";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$search=$_POST['barcode'];
$query = $pdo->prepare("SELECT * FROM xxx WHERE xxx LIKE '$search' LIMIT 0 , 10");
$query->bindValue(1, "$search", PDO::PARAM_STR);
$query->execute();
$results = $query->fetch();
$smarty = new Smarty();
$smarty->assign('output', '$results');
$smarty->display('results.tpl') |
results.tpl
Code: | {include file='globalheader.tpl'}
<div id="xx">
{$output}
</div>
{include file='globalfooter.tpl'} |
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Feb 23, 2016 1:08 am Post subject: |
|
|
While you are "trying to get basics working", don't touch Smarty at all.
Smarty is here to help you show off, not to make your code work. |
|
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
|