pastit Posted November 21, 2009 Share Posted November 21, 2009 I have a comma separated list of colors taken from a database ($ICo) and a directory of images named "color". The images are named the "color.jpg" I am attempting to loop through this list and display the corresponding image from the directory in a table with the color name below it. I am unable to get it to loop through the list, it displays the correct number of images but they are all the first image with the name under it. The script I have at this stage is $columns = 5; $Color = "$ICo"; $col = explode(",", $Color); $num = count($col)-1; echo "<table border='0' cellspacing='2' cellpadding='0'>\n"; for($i = 0; $i < $num; $i++) { if($i % $columns == 0) { echo "<tr>\n"; } $Name = $col[0]; $pic = "../store/color/$Name.jpg";} echo "<td align=\"center\" valign=\"top\" width=\"70\" ><img src=\"$pic\" name=\"$Name\" border=\"1\" width=\"68\" height=\"36\"><br>$Name</td>\n"; while ($num >= $col); if(($i % $columns) == ($columns - 1) || ($i + 1) == $num) { echo "</tr>\n"; } echo "</table>\n"; I have spent hours trying to figure out where I am going wrong. I know the line "$Name = $col[0];" is incorrect, could somebody please point me in the right direction Link to comment https://forums.phpfreaks.com/topic/182354-help-with-looping/ Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 Change $Name = $col[0]; to $Name = $col[$i]; Link to comment https://forums.phpfreaks.com/topic/182354-help-with-looping/#findComment-962305 Share on other sites More sharing options...
pastit Posted November 21, 2009 Author Share Posted November 21, 2009 Thanks so much AlexWD, works just fine Spent hours looking at that and couldn't see it Link to comment https://forums.phpfreaks.com/topic/182354-help-with-looping/#findComment-962386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.