Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 10-11-2007, 04:53 PM   #1
RedShoe
赤い靴 call me 202-456-1111
 
RedShoe's Avatar
 
Industry Role:
Join Date: Feb 2001
Location: The Valley
Posts: 14,831
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.
__________________

SPECIALTY COSTUMES • PROPS • FX
Superheroes • Monsters • Robots
PM for details


For any manufacturing needs. Adult or otherwise.

aka BonsHigh on Insta
Bonsai weed plants


RedShoe is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2007, 05:20 PM   #2
RedShoe
赤い靴 call me 202-456-1111
 
RedShoe's Avatar
 
Industry Role:
Join Date: Feb 2001
Location: The Valley
Posts: 14,831
n e one?
__________________

SPECIALTY COSTUMES • PROPS • FX
Superheroes • Monsters • Robots
PM for details


For any manufacturing needs. Adult or otherwise.

aka BonsHigh on Insta
Bonsai weed plants


RedShoe is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2007, 05:27 PM   #3
Varius
Confirmed User
 
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
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.
__________________
Skype variuscr - Email varius AT gmail
Varius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2007, 05:35 PM   #4
RedShoe
赤い靴 call me 202-456-1111
 
RedShoe's Avatar
 
Industry Role:
Join Date: Feb 2001
Location: The Valley
Posts: 14,831
Quote:
Originally Posted by Varius View Post
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.
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.
__________________

SPECIALTY COSTUMES • PROPS • FX
Superheroes • Monsters • Robots
PM for details


For any manufacturing needs. Adult or otherwise.

aka BonsHigh on Insta
Bonsai weed plants


RedShoe is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2007, 05:42 PM   #5
Tempest
Too lazy to set a custom title
 
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
Quote:
Originally Posted by RedShoe View Post
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.
Tempest is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2007, 05:46 PM   #6
Varius
Confirmed User
 
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
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
__________________
Skype variuscr - Email varius AT gmail
Varius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-11-2007, 05:54 PM   #7
TheDoc
Too lazy to set a custom title
 
TheDoc's Avatar
 
Industry Role:
Join Date: Jul 2001
Location: Currently Incognito
Posts: 13,827
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"}
__________________
~TheDoc - ICQ7765825
It's all disambiguation
TheDoc is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.