Jump to content

[SOLVED] display image via array


cdoyle

Recommended Posts

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

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 like the correct way to display the image?

 

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 complete code.  Slot 2 is the one I've been testing with.

 
<?
    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>

Link to comment
https://forums.phpfreaks.com/topic/132496-solved-display-image-via-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.