Ok, I bought this code from someone else, and he is using a class for pulling the data out of a MySQL databases. I understand databases and calling data out of them, but not so much classes. He makes the calls like this:
$hits = $mysql->query("SELECT * FROM hits WHERE did='$did[did]' ORDER BY timestamp DESC");
Ok, so all is well. And then since it returns an array, he uses another call like this to pull each row:
$hit = $mysql->fetch_array($hits)
The entire code runs like this:
$hits = $mysql->query("SELECT * FROM hits WHERE did='$did[did]' ORDER BY timestamp DESC");
while($hit = $mysql->fetch_array($hits))
{
echo $hit[timestamp] . " : " . $hit[pid] . "<br>\n";
}
As you have probably guessed this is for a small hit counter.
So, here is the problem. I tried to move the above code to a FUNCTION, like this:
function ($did)
{
$hits = $mysql->query("SELECT * FROM hits WHERE did='$did[did]' ORDER BY timestamp DESC");
while($hit = $mysql->fetch_array($hits))
{
echo $hit[timestamp] . " : " . $hit[pid] . "<br>\n";
}
}
and then I got the error message:
Fatal error: Call to a member function on a non-object in /hsphere/local/fcn-hits.php on line 18
Which directly references the line that makes that class call.
Please help! I don't know anything about classes! 🙁
Take care,
... Christopher