View previous topic :: View next topic |
Author |
Message |
Häakon Smarty Rookie
Joined: 19 Jul 2003 Posts: 18 Location: San Diego, California
|
Posted: Mon Sep 08, 2003 11:46 pm Post subject: Calling MySQL Data |
|
|
I've called up my query using the following command:
<?
$query = "select * from schools";
$schools = sql_query($query);
?>
But I'm getting lost as to where I'm supposed to use regular PHP syntax vs. smarty syntax. How would I display rows of data from a table that meet a specific column requirement with smarty code? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Sep 09, 2003 12:46 am Post subject: Re: Calling MySQL Data |
|
|
Häakon wrote: | How would I display rows of data from a table that meet a specific column requirement with smarty code? |
Can you elaborate? The idea is that you filter you query and build an array of results which you then assign to a smarty template variable. You can then use {foreach} or {section} to iterate the result array. BUT I am not following the intent of your question. |
|
Back to top |
|
Häakon Smarty Rookie
Joined: 19 Jul 2003 Posts: 18 Location: San Diego, California
|
Posted: Tue Sep 09, 2003 12:55 am Post subject: |
|
|
Okay, I have a MySQL table set up with a bunch of schools in it. One of the columns is "state," being the state that the school belongs to. I would like to run a query and display only the schools that belong to the particular state being called for (a variable that is passed from the previous page, called $thestate). I can get the variable to pass just fine, but I don't know how to sort out the data from the MySQL query. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Sep 09, 2003 7:59 pm Post subject: |
|
|
Haakon, the way I read this, this doesn't have anything to do with Smarty but instead is a SQL related question. You need to look up the WHERE clause as well as the ORDER BY clause of the SELECT statement. |
|
Back to top |
|
Häakon Smarty Rookie
Joined: 19 Jul 2003 Posts: 18 Location: San Diego, California
|
Posted: Tue Sep 09, 2003 9:14 pm Post subject: |
|
|
Maybe I'm just in over my head. Thanks for the help, though. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Sep 09, 2003 9:30 pm Post subject: |
|
|
No, not at all. Keep at it and eventually things won't seem so jumbled together |
|
Back to top |
|
Häakon Smarty Rookie
Joined: 19 Jul 2003 Posts: 18 Location: San Diego, California
|
Posted: Tue Sep 09, 2003 10:09 pm Post subject: |
|
|
I guess I just don't understand when I'm supposed to use normal PHP vs. Smarty stuff... and what the point of Smarty even is... I thought it would basically just allow me to do all of my PHP stuff with easier to understand tags, but now i'm stuck making two pages for every one that I want to code (a php page and a template one). As far as the stuff I've read about it, it seems perfectly suited for my needs... but I think I might be better off just using PHP by itself and not try to tackle learning two whole languages at once. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Sep 09, 2003 10:51 pm Post subject: |
|
|
I see your point. I also think it is harder to learn several languages and topics at once
In a nutshell, here is what I think Smarty is meant for. Basically, there are situations where you would want to separate the parts of your programs that produce and manipulate data from the parts of your program that display data. Smarty gives you a consistent way of creating the display portions of your application as templates. The other part of your application is left to your PHP code. It is not necessary for every project, but there are many times when this proves useful. Obviously thats a simplistic description, but that's the basic premise--Smarty is a means to separate your "application logic" from your "display logic".
You can indeed code into your Smarty template other logic that deals with data handling and such--but as a general rule, this is seen as defeating the purpose of using Smarty. So yes, it may be a bit premature to be using Smarty at this stage because Smarty is not meant to be used instead of PHP--it is meant as a tool to be used with PHP. Get your PHP code up to snuff and when you are ready to take the step of separating the display portions from the rest of your application, take another peek at all the ways Smarty will help you do that
cheers |
|
Back to top |
|
|