how to execute method and store the value in variable

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
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

how to execute method and store the value in variable

Post by pleigh »

hi, i was just wondering if i can store the value of the method in a variable. to make it clear, for examplpe i have a button with a method myMethod(), when i open a php page, that method is executed immediately even before clicking the button, and the value of that method will be stored inside a variable.

many thanks :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yes.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

thanks. may i ask for an example code? :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

May we ask for the existing code first?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There are many examples in the manual, I would also bet that you have many examples in your code already.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

hi, thanks for the replies...an example method (available in php) will be appreciated.:)

if myMethod will generate a value "some values, some values, still some values", i just want that value to be stored in a variable the moment i open the php page.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

POST YOUR CODE
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

ok thank you. here's the method

Code: Select all

getlog();
and here's the generated value of that record
reports.php?tab=td&rpt=16&sort=monthly&sortmonth=&sortweek=&startdate=&enddate=
before generating that value, i need to click on the button to trigger the getlogs() method. what i need to do is that when the page is loaded first time, that value will be generated and store it to a variable without clicking the button.

thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Use the assignment operator to store the return value of a function or method in a variable.
see http://de2.php.net/manual/en/language.o ... gnment.php
Post Reply