Jump to content

[SOLVED] Counting and Displaying Accordingly


JSHINER

Recommended Posts

I have a field in my database "number_photos" and lets say for example that number is 4.

 

I want to make it so if # of photos = 4, it will display:

 

photo_0.jpg

photo_1.jpg

photo_2.jpp

photo_3.jpg

 

I was going to use foreach to do this, but it does not work / I don't think it is the correct way.

 

So next I thought I would do:

 

$p = # of photos
$p++

 

To count up - but I need it to start at 0, and also need it to display the photo_0.jpg, etc.

 

I am stuck. Any suggestions?

Using the following:

 

<?php

$number = $page['details']['NO_PHOTOS'];

//The loop.

for($i=0; $i<$number; $i++){
$image[$i] = "photos[$i]=\"dir/medium/".substr($page['details']['LIST_NO'], 0, 2)."/".substr($page['details']['LIST_NO'], 2, 3)."/".substr($page['details']['LIST_NO'], 5, 3)."_".$i.".jpg\"";

}

//Display everything.

foreach($image as $key=>$val){
echo $val."<br />";
}

?>

 

I get the error: "Invalid argument supplied for foreach() in ...

 

Do you know the issue?

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.