GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Who here knows Smarty? I have a quick question (https://gfy.com/showthread.php?t=775847)

RedShoe 10-11-2007 04:53 PM

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.

RedShoe 10-11-2007 05:20 PM

n e one?

Varius 10-11-2007 05:27 PM

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:

RedShoe 10-11-2007 05:35 PM

Quote:

Originally Posted by Varius (Post 13223056)
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:

I guess, that's the part that boggles my mind.
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.

Tempest 10-11-2007 05:42 PM

Quote:

Originally Posted by RedShoe (Post 13223097)
I guess, that's the part that boggles my mind.
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.

Download and check out the example they have of how to do things... Yes, Smarty doesn't "need" MySQL.. but if you're site needs data then your site needs MySQL.. I've only just started using Smarty myself and am really liking it so far.

Varius 10-11-2007 05:46 PM

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 :)

TheDoc 10-11-2007 05:54 PM

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)
{
        $user = $_SERVER[PHP_AUTH_USER];
        $result = mysql_query("SELECT * FROM members WHERE username = '$user'");

  $password=$row["pass"];
  $smarty->assign ($params['xpassword'], $password);
  return ($password);
}


Call it like: {getpassword values="xpassword"}



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