Help with looping


Posted on 16th Feb 2014 07:03 pm by admin

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
Did you know?Explore Trending and Topic pages for more stories like this.
Code: $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">
$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
No comments posted yet

Your Answer:

Login to answer
101 Like 49 Dislike
Previous forums Next forums
Other forums

Forgot password won't work
My forgot password thing is not working properly. It is giving me this errorMailbox unavailable. The

Load Animated Image while cache is serve
I have a page that loads up using cache and took about 1 to 2 minutes before it loads to the page. <

Linkage between two scripts
Okay say I have this for a link in a script:

Code: <li><a href="#&q

chat
hello i'm amir i need a chat source code in asp.net 2.0 without Ajax. anybody can help me?

SCO Unix
I know this might not be the place to ask, but, can anyone tell me if SCO Unix comes with PHP built

How to sum these output values
Hi

I need sum the month totals
SELECT region_name, area_name ,SUM (CASE WHEN S

MII Trends - add data onto chart object
Hello,

Can anyone please provide some thoughts on my current requirement:
its pretty

selection tool on raster image
Hi!
I have to implement in my app a selection tool which lets users to select region of any shape

Need help/w Page: 1,2,3,4 function!
So I have this code im working on where it's ment to display seperate pages having 20 logs each
I

Curly Bracket Delimeters.
I'd always believed that the starting and ending delimeters in preg_ functions had to be the same ch

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash