Log in

View Full Version : Trying to create function that makes mysql call



junestag
10-19-2009, 07:07 PM
I want to use a user-defined variable that was created outside of a function INSIDE a function. How is this done?

Example:

$i = 0;

function CreateFields () {

echo "<div class=\"course" .$i. "\">";

$i++;

}

CreateFields();

but $i is not being recognized inside the function. Help?

traq
10-19-2009, 07:48 PM
$i = 0;

function CreateFields($i) {

echo "<div class=\"course" .$i. "\">";

$i++;

return $i; //sends the variable back *out* of the function
// (if that's what you want: I can't think of any other reason you'd increment it's value)

}

CreateFields();