0

Suppose I have 100 images, named 1.png,2.png,3.png...so on.

Is there any coding that it automatically increases the number.

For Eg, I have

<div class="col-md-2">
  <div class="thumbnail">
    <a href="<?php echo $details;?>6.php" target="_blank">
      <img class="img-zoom" src="<?php echo $images;?>6.png" alt="Lights" style="width:100%">
    </a>
  </div>
</div>

so now it should automatically do

<div class="col-md-2">
  <div class="thumbnail">
    <a href="<?php echo $details;?>7.php" target="_blank">
      <img class="img-zoom" src="<?php echo $images;?>7.png" alt="Lights" style="width:100%">
    </a>
  </div>
</div>

then

<div class="col-md-2">
  <div class="thumbnail">
    <a href="<?php echo $details;?>8.php" target="_blank">
      <img class="img-zoom" src="<?php echo $images;?>8.png" alt="Lights" style="width:100%">
    </a>
  </div>
</div>

and so on..

Auto increase number..

Chirag Jain
  • 1,367
  • 1
  • 11
  • 27

2 Answers2

3

You can use for loop for that.

Example:

<?php for ($i = 1; $i <= 100; $i++): ?>
<div class="col-md-2">
  <div class="thumbnail">
    <a href="<?php echo $details . $i;?>.php" target="_blank">
      <img class="img-zoom" src="<?php echo $images . $i;?>.png" alt="Lights" style="width:100%">
    </a>
  </div>
</div>
<?php endfor; ?>
Neodan
  • 5,154
  • 2
  • 27
  • 38
1

you could set it in the url parameters:

<div class="col-md-2">
  <div class="thumbnail">
    <?php $n = (isset($_GET['n'])) ? $_GET['n'] : 0; ?>
    <a href="<?php echo $details;?>?n=<?php echo $n+1 ?>.php" target="_blank">
      <img class="img-zoom" src="<?php echo $images . $n;?>.png" alt="Lights" style="width:100%">
    </a>
  </div>
</div>

EDIT: Guess i completely misunderstood the question I thought it had to increment every time the link was clicked

so for an alternative answer then the other 2

<?php foreach(range(1, 100) as $n): ?>

<div class="col-md-2">
  <div class="thumbnail">
    <a href="<?php echo $details . $n;?>.php" target="_blank">
      <img class="img-zoom" src="<?php echo $images . $n;?>.png" alt="Lights" style="width:100%">
    </a>
  </div>
</div>

<?php endforeach; ?>
DarkMukke
  • 2,469
  • 1
  • 23
  • 31