macnux wrote:
> and the $id is passed corerectly but the whle line
generates error why?
> when debug i found that $row_rs_father is null any idea?
Yes, the problem is one of variable scope. Variables inside a
function
are treated as though in a black box. This is to prevent
clashes with
any variables of the same name elsewhere in the script. The
$rs_father
inside your function is completely separate from the
$rs_father that
contains the result resource from MySQL.
If this sounds difficult to understand, try this sample
script:
$number = 2;
function doubleIt($number) {
return $number * 2;
}
$result = doubleIt(2);
echo $number; // displays 2
echo $result; // displays 4
The $number variable inside the function is completely
separate. In
technical terms, it's in a different scope.
For the recordset result to be available inside your
function, you need
to pass it as an argument to the function like this:
function getname($id, $recordset)
Inside the function, use $recordset instead of $rs_father.
HOWEVER...
It's not as simple as that. The way that Dreamweaver builds a
recordset
extracts the first row into a variable called
$row_recordsetName. That's
why repeat regions use a do... while loop, rather than a
straighforward
while loop.
So, passing the recordset resource to your function will omit
the first
row in the result set. You either need to delete the line at
the end of
the Dreamweaver recordset code that extracts the first row,
or to pass
the first row into the function and use a do... while loop
like Dreamweaver.
Another point to remember is that you cannot loop through a
recordset
more than once without using mysql_data_seek to reset it like
this:
mysql_data_seek($recordsetName, 0);
It's not clear to me why you want to create a function.
Functions
encapsulate routines that will be reused in multiple
situations. You're
attempting to use a specific recordset. Unless you need to
repeat this
process many times, it would be more sensible to dispense
with the
function, and just use an if... else conditional structure
and do...
while loop.
--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/