Need Help displaying image from array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Need Help displaying image from array

Post 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>
 
cdoyle
Forum Contributor
Posts: 102
Joined: Wed Feb 13, 2008 7:26 pm

Re: Need Help displaying image from array

Post by cdoyle »

Anyone know what's wrong with the code?
Post Reply