Page 1 of 1

Double loop from an array value

Posted: Thu Jun 25, 2009 11:02 am
by ehime
I have my array set up as

PHP Code:

Code: Select all

 
$token = uniqid();
$noko = array(0 => 'foreach value',1 => 'short name',2 => 'long name',3 => '');
 
I would like to take the amount of array/$noko[0] and write a loop that will
write two different strings. The first string will set up a stage of rollover
images:

HTML Code:

Code: Select all

 
<img alt='' onMouseOver="roll('<?=$src.$noko[1];?>-01-m.jpg','<?=$src.$noko[1];?>-01-m.jpg','<?=$token;?>','0');" src="<?=$src.$noko[1];?>-01-ico.jpg" />  
 
and the second loop will set up a stage of blank and arrow images:

first:
HTML Code:

Code: Select all

 
<img alt='' src="http://omnisistem.com/images/1up.gif" name="up_arrow_<?=$token;?>_0" />  
 
the rest:
HTML Code:

Code: Select all

 
<img alt='' src="http://omnisistem.com/images/pixel.gif" name="up_arrow_<?=$token;?>_1" /> 
 
I have quite a few incrementing values in here though and it is completely throwing
me off a loop. All of my image numbers need a pad_left zero, then my Javascript needs
a single digit value beginning from zero. I'm confused as to how I will pull this off honestly.
All I was able to accomplish was my last line that tells my loop/javascript how many
images it has:

PHP Code:

Code: Select all

 
<?php echo '<input type=\'hidden\' value="'.$noko[0].'" name="icoLength'.$token.'" />'; ?>
In the end, the output should look like this:

Code: Select all

 
 
<div class="ico"> 
<img alt='' onMouseOver="roll('<?=$src.$noko[1];?>-01-m.jpg','<?=$src.$noko[1];?>-01-m.jpg','<?=$token;?>','0');" src="<?=$src.$noko[1];?>-01-ico.jpg" /> 
<img alt='' onMouseOver="roll('<?=$src.$noko[1];?>-02-m.jpg','<?=$src.$noko[1];?>-02-m.jpg','<?=$token;?>','1');" src="<?=$src.$noko[1];?>-02-ico.jpg" /> 
<img alt='' onMouseOver="roll('<?=$src.$noko[1];?>-03-m.jpg','<?=$src.$noko[1];?>-03-m.jpg','<?=$token;?>','2');" src="<?=$src.$noko[1];?>-03-ico.jpg" /> 
<img alt='' onMouseOver="roll('<?=$src.$noko[1];?>-04-m.jpg','<?=$src.$noko[1];?>-04-m.jpg','<?=$token;?>','3');" src="<?=$src.$noko[1];?>-04-ico.jpg" /> 
<img alt='' onMouseOver="roll('<?=$src.$noko[1];?>-05-m.jpg','<?=$src.$noko[1];?>-05-m.jpg','<?=$token;?>','4');" src="<?=$src.$noko[1];?>-05-ico.jpg" /> 
<img alt='' onMouseOver="roll('<?=$src.$noko[1];?>-06-m.jpg','<?=$src.$noko[1];?>-06-m.jpg','<?=$token;?>','5');" src="<?=$src.$noko[1];?>-06-ico.jpg" /> 
</div>
 
<div class="arrow"> 
<img alt='' src="http://omnisistem.com/images/1up.gif" name="up_arrow_<?=$token;?>_0" />  
<img alt='' src="http://omnisistem.com/images/pixel.gif" name="up_arrow_<?=$token;?>_1" /> 
<img alt='' src="http://omnisistem.com/images/pixel.gif" name="up_arrow_<?=$token;?>_2" /> 
<img alt='' src="http://omnisistem.com/images/pixel.gif" name="up_arrow_<?=$token;?>_3" /> 
<img alt='' src="http://omnisistem.com/images/pixel.gif" name="up_arrow_<?=$token;?>_4" /> 
<img alt='' src="http://omnisistem.com/images/pixel.gif" name="up_arrow_<?=$token;?>_5" /> 
 
 
This is kinda silly I know.... But please help me out here since I do this function 1 to 30 times
a page I got lost somewhere. I got it working once, but then it crashed on all my lower products.

Re: Double loop from an array value

Posted: Thu Jun 25, 2009 4:46 pm
by McInfo
What HTML are you expecting from this? Can you post a sample with some dummy values in place of the PHP?

Edit: This post was recovered from search engine cache.