cdoyle Posted November 12, 2008 Share Posted November 12, 2008 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 More sharing options...
corbin Posted November 12, 2008 Share Posted November 12, 2008 print "<td width=\"33%\"><center><img src={$images[$slot[2]]}></td>"; (Print works with or without (). I prefer without.) Link to comment https://forums.phpfreaks.com/topic/132496-solved-display-image-via-array/#findComment-688946 Share on other sites More sharing options...
trq Posted November 12, 2008 Share Posted November 12, 2008 print "<td width=\"33%\"><center><img src=\"{$images[$slot[2]]}\"></td>"; Link to comment https://forums.phpfreaks.com/topic/132496-solved-display-image-via-array/#findComment-688949 Share on other sites More sharing options...
cdoyle Posted November 12, 2008 Author Share Posted November 12, 2008 Thank You!!! Link to comment https://forums.phpfreaks.com/topic/132496-solved-display-image-via-array/#findComment-688951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.