Page 1 of 1
Help with functions...pleasse!
Posted: Wed Jul 03, 2002 9:05 am
by kevin
Hi all
In PHP created two functions and another section of code to call these function. However what I'm finding is that the first function is been called (which is wrong) the second function isn't been called (which is correct). But the code calling the functions are not been called. I' using PHPed if that helps.
I'm new to PHP and is trying to set something up using PHP and mySQL.
Any and all help will be greatly appreciated.
Posted: Wed Jul 03, 2002 9:15 am
by RandomEngy
Give us your code and it will be much easier to tell what's going wrong.
Help with functions...pleasse! 2
Posted: Wed Jul 03, 2002 9:25 am
by kevin
The general format of the code is like this....
function a()
{
echo "a-in";
// some other code
echo "a-out";
return(1); // exmaple return value
}
function b()
{
echo "b - in";
// some other code
echo "b-out"
return(0); // exmaple return value
}
// code to call functions
if (a)
{
ehco "a-called";
}
if (b)
{
ehco "b-called";
}
// the problem is that all I ever see is a-in a-out nothing else.
// hope this helps
Posted: Wed Jul 03, 2002 9:54 am
by RandomEngy
I noticed a few things, like ehco instead of echo, no semicolon after echo b-out, and a instead of a(). The parenthesis tell PHP that a() is a function.
Try something like:
Code: Select all
$check = a();
if($check)
echo "a has run";
$check = b();
if($check)
echo "b has run";
Posted: Wed Jul 03, 2002 9:56 am
by BDKR
In your example
Code: Select all
if(a)
{ echo "a-called"; }
Is "a" supposed to be a variable?
Later on,
BDKR
Help with functions...pleasse! 3
Posted: Wed Jul 03, 2002 10:04 am
by kevin
sorry for the crap syntax.
haven't programmed in C/C++ for years...I know about a() for functions instead of a. The syntax is correct. It's just the flow of execution that seems to be the problem. Learning to touch-type at the moment everything I type seems to come out crap.
Posted: Wed Jul 03, 2002 4:44 pm
by defHex
the code works as it should.
a() returns 1. and b() returns 0. 1 is the equivalent of true, and 0 is the equivalent of false.
if(true){
//gets executed
}
if(false){
//doesn't get executed
}
if you were trying to test if the functions a and b exist, use function_exists()......
-defHex