Hello, i've been trying to get a value from a class but i cant get it to work.
I've got 2 files, one called index.php and the other class.php.
Ill show you what i've been trying to do.
<?php
//index.php
include("class.php");
$class = new class();
$result = $class->name();
echo $result; // <--- should be the value from class.php, but nothing gets printed!!!
?>
So im gonna get the value from class.php from the 'name()' function.
class class
{
function name()
{
$select = "SELECT name FROM table WHERE value = '1' ";
$query = mysql_query($select);
while($obj = mysql_fetch_assoc($query))
{
$name = $obj->name;
}
echo $name . " in class.php"; //this gets displayed.
return $name;
}
}
So the problem here is, is that i cant call $name that is in class.php from index.php.
Can someone tell me what im doing wrong...???