Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to have a Slideshow for each item.

It is only working with the first one, for the others it doesn't work.

Any idea what I'm doing wrong??

My code:

<?php
            // check $items variable exists and is not empty
            if(isset($items) && !empty($items)) :
                // init item count
                $count = 1;
            ?>
            <div class="shelf">

                <?php foreach($items as $key=>$item): ?>
                    <?php
                    // calculate if this item is the last on the shelf
                    // if item number can be divided by 5 with no remainders
                    $last_item = ( (($count) % 5 == 0)? 'item-last' : '' );
                    ?>

                    <div class="item <?php echo $last_item; ?>">
                        <a href="/items/view/<?php echo $item['Item']['slug']; ?>">
                        <p><?php echo $item['Item']['name'] ?></p>




                    <div id="CustomSlideshow">  


<?php
if ($item['Item']['vidsite'] = 'Pornhub') {

for($i=1;$i<=16;$i++) {
   $array[] = str_replace('.jpg',sprintf("%01d",$i).'.jpg',$item['Item']['vidimgdir']);
} ?>
<img src="<?php echo($array[0]); ?>"/>
<img src="<?php echo($array[1]); ?>"/>
<img src="<?php echo($array[2]); ?>"/>
<img src="<?php echo($array[3]); ?>"/>
<img src="<?php echo($array[4]); ?>"/>
<img src="<?php echo($array[5]); ?>"/>
<img src="<?php echo($array[6]); ?>"/>
<img src="<?php echo($array[7]); ?>"/>
<img src="<?php echo($array[8]); ?>"/>
<img src="<?php echo($array[9]); ?>"/>
<img src="<?php echo($array[10]); ?>"/>
<img src="<?php echo($array[11]); ?>"/>
<img src="<?php echo($array[12]); ?>"/>
<img src="<?php echo($array[13]); ?>"/>
<img src="<?php echo($array[14]); ?>"/>
<img src="<?php echo($array[15]); ?>"/>
<?php
 $array=array();
 } ?>


</div>                      

                        </a>
                    </div>

                    <?php
                    // if this is the last item, close the shelf div and create a new one
                    if(!empty($last_item)) {
                        echo '<div class="clear"></div>';
                        echo '</div>';
                        echo '<div class="shelf">';
                    }
                    ?>
                <?php $count++; ?>
                <?php endforeach; ?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted
if ($item['Item']['vidsite'] = 'Pornhub') {

My guess is you have forgotten one equality sign, so your code keeps assigning the same value to $item['Item']['vidsite'].
One equality sign (=) assigns the value to the item, two (==) compare the operand, thus you should replace = with ==.
Perhaps you already knew this and have just mistyped it. Don't worry, I also used to make this mistake. ;)


And by the way - if I were you, I'd replace the following code:

for($i=1;$i<=16;$i++) {
   $array[] = str_replace('.jpg',sprintf("%01d",$i).'.jpg',$item['Item']['vidimgdir']);
} ?>
<img src="<?php echo($array[0]); ?>"/>
<img src="<?php echo($array[1]); ?>"/>
<img src="<?php echo($array[2]); ?>"/>
<img src="<?php echo($array[3]); ?>"/>
<img src="<?php echo($array[4]); ?>"/>
<img src="<?php echo($array[5]); ?>"/>
<img src="<?php echo($array[6]); ?>"/>
<img src="<?php echo($array[7]); ?>"/>
<img src="<?php echo($array[8]); ?>"/>
<img src="<?php echo($array[9]); ?>"/>
<img src="<?php echo($array[10]); ?>"/>
<img src="<?php echo($array[11]); ?>"/>
<img src="<?php echo($array[12]); ?>"/>
<img src="<?php echo($array[13]); ?>"/>
<img src="<?php echo($array[14]); ?>"/>
<img src="<?php echo($array[15]); ?>"/>

with this one:

for($i=0;$i<=15;$i++) {
   $array[] = str_replace('.jpg',sprintf("%01d",$i).'.jpg',$item['Item']['vidimgdir']);
   echo '<img src="'.$array[$i].'"/>';
} ?>

Much shorter.

share|improve this answer
    
Thanks a lot, it's working now.. –  grosseskino Apr 19 '11 at 15:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.