Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Help... New to Smarty - Need to use data from MySQL

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Steevi93
Smarty n00b


Joined: 13 Jan 2020
Posts: 2

PostPosted: Thu Jan 16, 2020 12:00 pm    Post subject: Help... New to Smarty - Need to use data from MySQL Reply with quote

Howdy:

First post, so please be gentle. I'm currently a level 5 student and I'm looking for help with a PHP website that I'm designing.

It was recommended that I use Smarty templates, so I have installed everything, and played around with it somewhat using documentation that I was provided, to basically get used to the template way of doing things.

I have a database where I need to display images and character names from Star Wars (I'm basically trying to create a "Guess Who" game).

However, I cannot see to find any documentation on how I can go about this. The database is done, I have the relevant select SQL command, and I have connected to my database in PHP successfully.

I come from a technical support background and am a complete novice when it comes to software development. I'm normally fixing things, not creating them, lol. I don't want code written for me... just some tips on where I could find guidance.

Thanks in Advance!
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 265
Location: West Coast

PostPosted: Sun Jan 19, 2020 7:55 am    Post subject: Reply with quote

This documentation page sets up a resource that communicates with a database and provides samples of how to get templates from that resource:
https://www.smarty.net/docs/en/resources.custom.tpl

But this explains how to retrieve templates from this resource, not retrieve data to populate a template.

To retrieve data from the database and populate the template with it, then the assign() method is used.
Code:

-- Pseudo-code --
$recordset = "SELECT WHAT YOU NEED";
$smarty->assign("SOME_TEMPLATE_VAR_NAME", $recordset);

-- Template --
{$SOME_TEMPLATE_VAR_NAME}
Back to top
View user's profile Send private message
Steevi93
Smarty n00b


Joined: 13 Jan 2020
Posts: 2

PostPosted: Mon Jan 20, 2020 11:25 am    Post subject: Reply with quote

bsmither wrote:
This documentation page sets up a resource that communicates with a database and provides samples of how to get templates from that resource:
https://www.smarty.net/docs/en/resources.custom.tpl

But this explains how to retrieve templates from this resource, not retrieve data to populate a template.

To retrieve data from the database and populate the template with it, then the assign() method is used.
Code:

-- Pseudo-code --
$recordset = "SELECT WHAT YOU NEED";
$smarty->assign("SOME_TEMPLATE_VAR_NAME", $recordset);

-- Template --
{$SOME_TEMPLATE_VAR_NAME}


Thank you. I will peruse that now.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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