Search code examples
phpmysqlmarquee

mysql scrolling marquee works but I have an error


I have a marquee displaying mysql data. The marquee works perfectly but I get:

Notice: Undefined variable: cont in include() (line 51)

Here is the code I am using.

 while($row = mysql_fetch_array($result))
    {

    $fundid=$row['Fund_ID'];
    $fundname=$row['Fund_Name'];
    $mostrecentnav=$row['Most_Recent_Nav'];
    $lastdaychange=$row['Last_Day_Change'];
    $lastdayyield=$row['Last_Day_Yield'];

        $cont.= "<a style='color:#0066CC;' href=\"fund-?id=$fundid\">$fundname</a>&nbsp;<b>NAV:</b>$mostrecentnav, <b>Cambio del nav en el dia:</b>$lastdaychange, $lastdayyield% &nbsp;&nbsp; ";
}
    echo "<marquee scrollamount='3' scrolldelay='1' onmouseover='this.stop();' onmouseout='this.start();'>$cont</marquee>";


mysql_close($con);

What needs to be changed to get rid of the error. The variable is defined otherwise the query wouldn't work. Thank you.


Solution

  • $cont = ''; before the while() loop will fix that. you're implicitly USING $cont before it's been set, the first time you execute:

    $cont .= ...;
    

    which is equivalent to

    $cont = $cont . ....;
            ^^^^^---undefined on first iteration.