vikinggirl*** Posted November 26, 2006 Share Posted November 26, 2006 This is my first loop in php... It is supposed to do the following: 1) Read some images into an array.2) Create a table 3) Create x number of rows in the table (x = a variable set elsewhere. Right now it is hard coded.) 4) Each new row is to contain one randomly chosen image, from the array that was created in 1). At the moment, the loop isn't looping!It only runs one instance of the loop. So there is only one row created I think, at least only one images is displayed.(I don't know any way of stepping through php code, so i don't know how to troubleshoot any further!)What is wrong with this simple loop? It should run 4 times because of the hardcoded values. [CODE]<?php$images=array('vulgare.png', 'blueberry.png' ,'kantarell.png',);?><?php echo "<table class=\"sidebartable\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" >";for ($counter = 0; $counter <= 4; $counter += 1); $rand=rand(0,3); $image=$images[$rand]; {echo "<tr><td>"; echo"<img src=$image>"; echo "</td></tr>";}?></table>[/CODE] Quote Link to comment Share on other sites More sharing options...
taith Posted November 26, 2006 Share Posted November 26, 2006 [code]<?php$images=array('vulgare.png', 'blueberry.png' ,'kantarell.png',);echo "<table class=\"sidebartable\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" >";for($counter = 0; $counter <= 4; $counter++){ $image=$images[rand(0,3)]; echo "<tr><td>"; echo"<img src=$image>"; echo "</td></tr>";}?></table>[/code]EDITED BY thorpe; Please use long <?php tags within the [ code ] blocks, this enables syntax highlghting. You should be using it within your code anyway! Quote Link to comment Share on other sites More sharing options...
vikinggirl*** Posted November 26, 2006 Author Share Posted November 26, 2006 Great! Thanks for posting the fixed code! Works fine! I see what I did wrong. I guess by long php codes you mean compressed php, no spaces, carriage return etc? I'll bear that in mind in the future. Jo Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.