Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Looping through an array


hyperweb

Recommended Posts

First time poster, I hope this is the right thread as I seem to be having some trouble, 

 

I am new to OsCommerce, as I have just picked up a client who has used this platform for some 13 years.

 

I am trying to loop this bit of html. 

<div class="ms-slide">
    <?php echo tep_image('images/' . $product_info['products_image'], addslashes($product_info['products_name'])); ?>						
    <img class="ms-thumb" src="images/<?php echo $product_info['products_image'];  ?>" alt="thumb" />
</div>

I need this loop to look like this on output  : 

<div class="ms-slide">
     <img src="image/main.jpg"  />				
     <img class="ms-thumb" src="image/main.jpg" alt="thumb" />
</div>

<div class="ms-slide">
     <img src="image/01.jpg"  />				
     <img class="ms-thumb" src="image/01.jpg" alt="thumb" />
</div>


<div class="ms-slide">
     <img src="image/02.jpg"  />				
     <img class="ms-thumb" src="image/02.jpg" alt="thumb" />
</div>

However, I seem to be having a really hard time figuring out how to write a forEach loop regarding the product images.

 

This output would give me my image slide and thumbnails on the product_info.php page. 

 

There are no modules in the way to interfere, I themed a copy of the bootstrap edition and I am trying to integrate the product images into my display theme properly.

 

Any help is appreciated! Thanks in advance!

 

Link to comment
Share on other sites

@@hyperweb

 

This is the original code, what are you having difficulty with? Why do you want to change it? To make the images into a slider rather than static?

 

(this is assuming you are using the recommended 2.3.4BS version)

<?php
    if (tep_not_null($product_info['products_image'])) {
      echo tep_image('images/' . $product_info['products_image'], NULL, NULL, NULL, 'itemprop="image" style="display:none;"');
      $photoset_layout = (int)MODULE_HEADER_TAGS_PRODUCT_COLORBOX_LAYOUT;
      $pi_query = tep_db_query("select image, htmlcontent from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order");
      $pi_total = tep_db_num_rows($pi_query);
      if ($pi_total > 0) {
?>

    <div class="piGal pull-right" data-imgcount="<?php echo $photoset_layout; ?>">

<?php
        $pi_counter = 0;
        $pi_html = array();
        while ($pi = tep_db_fetch_array($pi_query)) {
          $pi_counter++;
          if (tep_not_null($pi['htmlcontent'])) {
            $pi_html[] = '<div id="piGalDiv_' . $pi_counter . '">' . $pi['htmlcontent'] . '</div>';
          }
          echo tep_image('images/' . $pi['image'], '', '', '', 'id="piGalImg_' . $pi_counter . '"');
        }
?>

    </div>

<?php
        if ( !empty($pi_html) ) {
          echo '    <div style="display: none;">' . implode('', $pi_html) . '</div>';
        }
      } else {
?>

    <div class="piGal pull-right">
      <?php echo tep_image('images/' . $product_info['products_image'], addslashes($product_info['products_name'])); ?>
    </div>

<?php
      }
    }
?>

osCommerce user since 2003! :thumbsup:

Link to comment
Share on other sites

And are you going to post what you did so that it may be beneficial to others who find this thread and want to see what the final outcome was.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

@@hyperweb

 

What makes the wealth of our community is sharing.
When you have a problem and a community member takes time to help, the least is to give the final result so that it can help someone who is going to have the same problem.

with OsC 2.2 since 2006 ...

Link to comment
Share on other sites

@@14steve14

 

Not really interested. This community seems toxic.

 

Yo, bud, that's how community-supported software works! If you ask a question and someone takes the time and effort to try to help, the least you can do is let us know what solution you found, to aid others who come after you. 

Link to comment
Share on other sites

@@MrPhil

 

I asked a simple question. 

 

I received two very condescending replies. 

 

Why would I be interested in helping at this point?

 

User @@frankl pointed out what I discovered myself the night before. Which was a simple misplaced location of where the looping was taking place.

 

I was slightly unfamiliar with this old school way that OsCommerce was built.

 

I refreshed my own memory, and discovered what I needed to. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...