Jump to content

[SOLVED] Function help


pzt_penguin

Recommended Posts

Hi,

I'm having a problem with using a object in a function.

<?
include 'test_db.php';

$query = ("Select * From $mytable WHERE username='$username'");
$data_result = mysql_query($query);
$data = mysql_fetch_object($data_result); 

$data->gamesplayed=3;
$data->gamesplayed++;
echo "Games played before function = $data->gamesplayed<br>";

function test($name) {
global $data,$opponent;
echo "games played before = $name->gamesplayed<br>";
$name->gamesplayed=5;
return $name->gamesplayed;

}

$bb=test($data);
echo "your games played now = $bb<br>";
echo "Games played after function = $data->gamesplayed";
?>

output

Games played before function = 4
games played before = 4
your games played now = 5
Games played after function = 4

 

My question is why dose data->gamesplayed go back to 4 after I run the function?

I need it where data->gamesplayed will hold what alterations the function makes.

Also when I use the function by just calling it like test($data) it still stays at 4.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/38379-solved-function-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.