Hi,
I've tried to do simple function for changing a css class dependant on the variable passed to the function.
function get_style($who) // $name from predictions table
{
$style = "user"; // default style.
if( $who == $login ) // is this the logged in user?
{
$style = "thisuser";
}
return $style;
}
then, for each row in the resultset of a db query, I call the function to determine $style like so:
while ($row = mysql_fetch_array($sql_result)) {
$name = $row["name"];
(etc etc for all other columns);
$style = get_style($name);
echo "<TR>
<TD class=$style>$name</TD>
</TR>";
}
$login is the existing user's session id login name.
there is one row in the resultset where $name matches $login.
each time I run it, $style is being returned as "user", even when $name = $login.
any help appreciated. TIA.
Grifter
First attempt at Function - Help!
Moderator: General Moderators
where do you set $login ?
functions have no access to global scope by default.
http://www.php.net/manual/en/language.variables.scope.php
functions have no access to global scope by default.
http://www.php.net/manual/en/language.variables.scope.php