So, I have a newbie syntax question, sorry to bother you with noddy stuff.

I have fetched a set of results from a database quesry using
mysql_fetch_object. I want to iterate through a subset of the columns
from each result, as defined by a separate array. I don't seem to be
able to find the correct syntax for referencing the specific property
of the object with a variable name.

Here's my broken code:

$tabarray = array("bio", "research", "publications", "supervision");
$staffdata = mysql_fetch_object( $result );

foreach ( $tabarray as $tab ) {

        echo "<li>$staffdata->$tab</li>\n";

}

Hope that's clear what I'm trying to do. I know I could iterate
through every database column and discard any column not in tabarray
or use eval() to build a line of code that did the trick but I'm sure
there must be a more elegant way to get $staffdata->$tab to
interpolate to $staffdata->bio etc and I'm just too inexperienced to
know what it is.

Thanks in advance for your help folks.

-- 
BD

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to