Page 1 of 1

Can a function call itself?

Posted: Tue Jan 07, 2003 6:20 am
by Rincewind
I'm trying to make a message-board (much like this one) and I'm clear on how I'm gonna list messages in the main window, also messages have a parent-id in the database, discerning what message it is an answer to, and each message has an int in the database telling how many childen-messages it has.

My problem is that a childen-message can have children and children of children of children...
So how do I loop through them to get them to list correctly below the right message?
One possible sollution is having a function listing 1 message with input message-id, then calling itself subsequently when it lists a message with a child...is this doable?
Can a function call itself??

Thanx

Rincewind_the_Wizzard

Posted: Tue Jan 07, 2003 8:04 am
by Bill H
It's called "recursion" or a "recursive function call."

I just did a search on the term in the PHP manual and did not find it, so I can't tell you whether PHP allows it or not. Some languages do (i.e. C/C++), some do not.

Why don't you just give it a try and see what happens?

Just did...

Posted: Tue Jan 07, 2003 8:24 am
by Rincewind
As a matter of fact that was my reason for coming here now, to say: Nevermind, it works...
So php allows it apparently :)
I was trying it, just didn't get it to work, so I posted here to find out if I was working at an impossible angle, but I was just being stupid, works now....

Thanx anyway :)