Hi All,
I've written a function and put a while loop inside it like so:
function myFunction(){
$SQL = "SELECT * from tbl order by id desc LIMIT 2";
$result = mysql_query($SQL) OR die(mysql_error());
$active = "active";
$inactive = "inactive";
$n=1;
while ($row = mysql_fetch_assoc($result))
{
$headline[] = $row['headline'];
$active = ($active=='active' ? 'inactive' : 'active');
$inactive = ($inactive=='inactive' ? 'active' : 'inactive');
echo '
<div id="leaderPanel'.$n.'" class="leadContainer" style="display:inline">
<a class="leader-'.$inactive.'">'.$headline[0].'</a>
<a class="leader-'.$active.'">.'$headline[1].'</a>
</div>
';
$n++; }
}
?>
However, I get the message [] operator not supported for strings here:
$headline[] = $row['headline'];
Is there a reason why it won't work in a function and how would I get around this?
Thank you.