|
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 |
Steevi93 Smarty n00b
Joined: 13 Jan 2020 Posts: 2
|
Posted: Thu Jan 16, 2020 12:00 pm Post subject: Help... New to Smarty - Need to use data from MySQL |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sun Jan 19, 2020 7:55 am Post subject: |
|
|
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 |
|
Steevi93 Smarty n00b
Joined: 13 Jan 2020 Posts: 2
|
Posted: Mon Jan 20, 2020 11:25 am Post subject: |
|
|
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 |
|
|
|
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
|