Functions Help?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Functions Help?

Post 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: :arrow: 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: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Functions Help?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Re: Functions Help?

Post 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 ...

:(
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Functions Help?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Functions Help?

Post 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.
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Re: Functions Help?

Post by jurklins »

I am not using wordpress. I am just curious how it is done..
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Re: Functions Help?

Post by jurklins »

I heard that using smarty will slow down the process a litle..Is wordpress even slower ??
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Functions Help?

Post 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
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Re: Functions Help?

Post by jurklins »

Ok thanks!
Post Reply