Page 1 of 1

Need Help displaying image from array

Posted: Tue Nov 11, 2008 2:18 pm
by cdoyle
Hi,

I found this script online for how to make a simple slot machine.
http://www.php-scripts.com/php_diary/122799.php3

So I got it working with the numbers fine, but now I'm trying to add the images to replace the numbers.

According to the instructions, I should add this

Code: Select all

print("<td width=\"33%\"><center><img src=$images[$slot[2]]></td>");
 
but as soon as I try this, netbeans highlights this as having a syntax error.

Does that look correct?

I've tried different things, but just cannot get it to work. I've tried searching for how to display an image via an array, but haven't really found anything.

Here is my code

Code: Select all

 
<?
    function slotnumber()
    {
        
        srand(time());
        for ($i=0; $i < 3; $i++)
        {
            $random = (rand()%3);
            $slot[] = $random;
            $images = array("lemon.gif","lemon.gif","lemon.gif");
        }
        echo "<td width=\"33%\"><center>$slot[0]</td>";
        echo "<td width=\"33%\"><center>$slot[1]</td>";   
        echo "<td width=\"33%\"><center><img src=$images[$slot[2]]></td>";   
        if($slot[0] == 9 && $slot[1] == 9 && $slot[2] == 9) 
        {
            echo "</td></tr>Winner! -- Hit refresh on your browser to play again";
            
        }
    }
?>
 
<div align="center"><center>
    <table border="1" width="100%">
    <tr>
    
    <?
        slotnumber();
    ?>
    <?
       
    ?>
    </td></tr><tr>
    <td colspan="3">
    <form method="POST" action="slots.php">
        <div align="center"><center><p><input type="submit" value="Spin!">
        </p></center></div>
    </form>
 

Re: Need Help displaying image from array

Posted: Wed Nov 12, 2008 5:00 pm
by cdoyle
Anyone know what's wrong with the code?