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

Need Help With Smarty Templates!!! :)

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
phpkibbles
Smarty n00b


Joined: 03 Jun 2004
Posts: 1

PostPosted: Thu Jun 03, 2004 1:37 am    Post subject: Need Help With Smarty Templates!!! :) Reply with quote

Hi Everyone,

I am just starting to learn about Smarty templates, and I was referred to this site. I have absolutely no idea how to start off with what I'm trying to do.

What I am trying to do is apply a smarty template to the following php file:

<?php

include ('Smarty.class.php');

$smarty = new Smarty;


$link = mysql_connect('localhost', 'na002399', 'na002399');

if (!$link) {
die('Could not connect: ' . mysql_error());
exit;
}



$db_selected = mysql_select_db('na002399', $link);

if (!$db_selected) {
die ('Can\'t use na002399 : ' . mysql_error());
exit;
}


$query = "SELECT SalespersonName FROM Corder WHERE CustName = 'Abernathy Construction'";
$result = mysql_query ($query);

if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}

if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}



while ($row = mysql_fetch_assoc($result)) {

$SalespersonName = $row["SalespersonName"];

mysql_free_result ($result);

$smarty->assign ('name', $SalespersonName);

$smarty->display ('index.tpl');

?>


I know how to apply a smarty template when the information is hard coded but it confuses me when the data is coming from a database. All my data comes from a table in a database and I have no idea how to apply a smarty template to it.

Thanks to anyone who can help, Smile

phpkibbles
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Jun 03, 2004 2:19 pm    Post subject: Reply with quote

I think you were sent here because this is a topic that has been discussed many-a-time here. Please try searching the forums for some relevant material. There are also tutorials concerning mysql, adodb, etc with smarty that you can google for.

FWIW, your example is close--but you aren't fetching your table properly. Once you get a proper array setup, it is simply a matter of assigning it to Smarty and then using section or foreach from withing your template to iterate it. Like I said, there are many examples of this available, so please search.

Good Luck!
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 -> Tips and Tricks 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