Page 1 of 1
Functions Help?
Posted: Tue Apr 22, 2008 10:47 am
by jurklins
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi I am a total newbie and am trying to learn a bit of php . Please help!!
Current:
Code: Select all
while($result_row=$result->fetchRow())
{
echo $result_row[0]."-";
echo $result_row[1]."<br/>";
}
I would like to know how to separate them into
3 nice looking functions so that it will turn out nice like this like a wordpress loop:
What I want:
Code: Select all
while(have_post())
{
post_column1();
post_column2();
}
I tried using string variables but wont work.lol
Please Help ! Thanks!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Re: Functions Help?
Posted: Tue Apr 22, 2008 11:20 am
by pickle
In my opinion, Wordpress should not be used as a coding standard to try & strive for. They've set up their template engine so as to be as simple as possible for designers to interpret. It is not a pillar of how things should be done.
Why do you want to change what you've got? For most cases, your code looks fine to me.
Re: Functions Help?
Posted: Tue Apr 22, 2008 2:26 pm
by jurklins
Thanks pickle for the reply.
I just want to change them , so that when i do html and css, all i need is encode a php tag and the function names to make it look cleaner ...

Re: Functions Help?
Posted: Tue Apr 22, 2008 3:41 pm
by pickle
So you want to (wisely) separate program logic from display logic?
Have you looked into template engines? I know this may be going beyond the scope of your initial question. However, if your goal is to properly build a script that is easy to update & theme in the future, the question is bigger than you initially posted.
To answer your initial question, you'd have to declare the result set global so you could access it between all your functions. I don't know, but I'd guess Wordpress loads all it's data first & stores it all in PHP variables, then those little functions are used to access those variables.
Re: Functions Help?
Posted: Tue Apr 22, 2008 3:55 pm
by Zoxive
pickle wrote:To answer your initial question, you'd have to declare the result set global so you could access it between all your functions. I don't know, but I'd guess Wordpress loads all it's data first & stores it all in PHP variables, then those little functions are used to access those variables.
Which slows down your application. It gives it more overhead (Making functions that access global variables that hold all of the data), I'm sure everyone here has seem many Wordpress sites down.
Re: Functions Help?
Posted: Tue Apr 22, 2008 4:47 pm
by jurklins
I am not using wordpress. I am just curious how it is done..
Re: Functions Help?
Posted: Wed Apr 23, 2008 11:11 am
by jurklins
I heard that using smarty will slow down the process a litle..Is wordpress even slower ??
Re: Functions Help?
Posted: Wed Apr 23, 2008 11:25 am
by pickle
Using a template engine will definitely slow down the process. That said, any code organization that causes you to use anything other than a single file with full procedural code will slow down the process. However, one has to decide if a particular way of organizing code is worth the trade off in performance. Doing things like making class files is almost certainly worth the trouble. Usually, using a template engine is worth the trouble as well.
I have no idea how much of a performance hit Wordpress takes because of the way they chose to do their template engine. It's really tough to say because there's really no before & after testing available.
If you are looking at using a template engine, Smarty is the most popular. There is another library out that I and a couple other people really like called Template Lite. It's based off Smarty & is actually just a port of Smarty to a leaner, less process-intensive version.
Template Lite Homepage
Re: Functions Help?
Posted: Wed Apr 23, 2008 12:17 pm
by jurklins
Ok thanks!