Jason Wong wrote:
> On Monday 30 December 2002 22:07, Michael Sims wrote:
>> On Mon, 30 Dec 2002 14:48:13 +0100, you wrote:
>> >function setCurrentDevGroup($devID)
>> > {
>> >// start original routine
>> > $query = "SELECT dev_group FROM tracking WHERE (computer
>> > =
>> > $devID)"; $sth
>> > =
>> > $adb->prepare($query);
>>
>> [...]
>>
>> > Call to a member function on a non-object in
>> >/www/htdocs/dev/include/irm.inc on line 2857
>>
>> Just a guess, but where did $adb inside your function come from? It
>> doesn't appear that you've instantiated it.
>
> Specifically, if it's instantiated elsewhere in your code and it's in the
> global scope then you need to declare it as global within your function:
>
> function setCurrentDevGroup($devID) {
> global $adb;
> /// rest of function
> }
Yes, that was it. And also that I had misplaced the function in my gigantic
include file. Now it does what it is supposed to do, almost.
function setCurrentDevGroup($devID)
{
$query = "SELECT dev_group FROM tracking WHERE (computer = $devID)";
$sth = $adb->prepare($query);
if($sth)
{
$res = $sth->execute();
$resulttable = $sth->fetchrow_hash();
$lookuptable = $resulttable["dev_group"];
//I do get a value for lookuptable here, eg printers.
return($lookuptable);
}
}
But the value of $lookuptable isn't used in
switch ($lookuptable) {
case "computers":
$query = "SELECT name FROM computers
WHERE (ID = $this->ComputerID)";
break;
case "printers":
$query = "SELECT name FROM printers
WHERE (ID = $this->ComputerID)";
break;
}
(And yes I suppose you could write that as
"SELECT name from $lookuptable WHERE ....";
What am I missing now?
/Martin S.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php