Hello everyone.
I am pretty new to oop, so this might be a simple question.
I need to get data from my database and I need it in several different places on my site. So I decided to create a class to get the data instead of writing it over and over again.
now, the method i created is nothing but a mysql query and a while loop to get the variables:
function getGroupData(){
$result = mysql_query("SELECT * FROM groups ")
or die(mysql_error());
while($row = mysql_fetch_array($result)){
$id = $row["id"];
$groupname = $row["groupname"];
$groupurpose = $row["groupurpose"];
$groupmessage = $row["groupmessage"];
}
}
of course this sits inside a class and there is a "connect to my db.php" included...
the problem is that the variables (i.e $id, $groupname etc...)do not seem to exist outside of the method.
How can I use them in other methods and outside the method? I need a solution that can handle methods which create dozens of variables.
even if I declare them global (i.e global $id; global $groupname; etc...) before the mysql query, they still don't exist outside the method.
Thank you for your help!