![]() |
Who here knows Smarty? I have a quick question
according to this smarty doc, http://smarty.php.net/manual/en/config.files.php you can gain access to a mysql database.
And according to this doc, http://smarty.php.net/manual/en/api.config.load.php you can load those configs into the php file. But how do you tell the php which table to use within that database? I'm really new to php, smarty, and mysql. But from what I can gather in mysql and php, you connect to the mysql and then you connect to the table you want to call info from. So how do you do that with smarty? OR Is it better to just create a config file of an associative array of data? I asked that on the smarty board but after being on GFY for years all other boards move slow as shit. |
n e one?
|
You really shouldn't be mixing php code into your smarty templates as the whole purpose of smarty is to separate code from html.
However Smarty has no mysql functions I know of, so to do it in the template you would have to use {php}{/php} to allow you to execte php code and then use php's mysql functions like mysql_connect(), mysql_db_query(), etc... I recommend since you are starting though to start the right way and use adoDB or another db abstraction layer class to keep things portable and clean. Do your SQL in the php file and assign it to whatever variables you need to access it with in smarty. Don't tdo your SQL in the template. :2 cents: |
Quote:
Smarty prides itself on not needing mysql, and doesn't even offer a way to use mysql... so then how do you use databases? Can you even use databases? I want to create database of all our girls, and display them with Smarty and be able to sort them, and rate them, all that (in time). And I'm willing to kinda play with it and learn it myself, but I just don't see how you do that WITHOUT the use of mysql. |
Quote:
|
Red,
Quick example to help you out: (this part is in your php file, assuming you already connected to the Db etc...) $sql = "SELECT field1, field2 FROM table"; $result = $db->GetAll($sql); // This is if you are using adodb $smarty->assign('result',$result); (this is how you loop through that data in your template) {section name=a loop=$result} <tr><td>whatever HTML here</td><td>{$result[a].field1}, {$result[a].field2}</td></tr> {/section} Hope that helps :) |
You use smarty plugins. This allows you to create blocks of php that can do different functions, then call those functions to the template.
Often in /smarty/libs/plugins You normally don't have to mysql connect directly when using a plugin, but you can if you want to connect to a different db other than the local setup. As an example Code:
function smarty_function_getpassword($params, &$smarty) |
All times are GMT -7. The time now is 08:47 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123