Page 1 of 1
How to declare and call function?
Posted: Mon May 24, 2004 12:47 pm
by ljCharlie
I want to know how to create and call a function. Here's what I have. I have a PHP block of at the very begining of the page even before the <html> and then at the <body> tag, I declare the function as: function myfunction(){
do my stuff here including echo file download link
}
Then on the PHP block of code that's before <html>, I have myfunction() as my function calling.
Can anyone tell me if what I'm doing is right? If not, will you show me how?
Many thanks in advance!
ljCharlie
Posted: Mon May 24, 2004 1:03 pm
by magicrobotmonkey
does it work how you want it to?
Posted: Mon May 24, 2004 1:12 pm
by ljCharlie
Heres' what I want it.
Code: Select all
<?PHP
do my database connection and testing here
if ($btnDate =="Extract Date"){
queryByDate();
}
?>
<html>
<head></head>
<body>
<?PHP
function queryByDate(){
echo my links here
}
?>
</body>
</html>
When do this, the page would not display anything. Howver, if I combined both PHP block of code into one inside the body tag then it works just fine. Suggestions are much appreciated.
ljCharlie
Posted: Mon May 24, 2004 1:51 pm
by d3ad1ysp0rk
It isn't the fact that it's inside or outside, you must be doing something differently.
Make sure you're getting the value expected, and maybe add an else to that if statement with a msg to tell what it did (debug your script).
Posted: Mon May 24, 2004 2:06 pm
by ljCharlie
Thanks! I think I got it working.
ljCharlie
Posted: Mon May 24, 2004 2:08 pm
by ljCharlie
Oh, by the way, I have one more question.
In the <body> tag, I have the function echo something onto the page, however, since the function was called before the <html> tag, the echo is being displayed before the <html> and not the in the <body> tag where I put the function in. How do i solve this problem?
ljCharlie