Jump to content

Number Sequence


Arkane

Recommended Posts

Hey guys,

Sorry if the topic is misleading, I couldn't think of an explanation for this.

I'm trying to add images to my site automatically.  It's using numbers and I already have the code for most of it.  The problem is that the source images are kept in folders to seperate the files more.

My script adds the links according to a 4 digit number, but each file is kept in subfolders, so 0001.png is in imgs/0001-0250/, with the folders always increasing in 250 increments.  Can anyone help me for some script to calculate the number so that it can all be done automatically?

 

Cheers guys

Link to comment
https://forums.phpfreaks.com/topic/145496-number-sequence/
Share on other sites

Ok guys, here's the code I have atm.

		<?php  
		$startnum = isset($_GET['startnum']) ? $_GET['startnum'] : '0001';
		$endnum = $startnum + 99;
		$books = new SimpleXMLElement('NDS.xml', null, true);  

		echo '<h2>'.sprintf('%04d', $startnum).' to '.sprintf('%04d', $endnum).'</h2><p>'.PHP_EOL;

		$titles = $books->xpath('games/game');
		foreach($titles as $title)
		{  
		    $num = $title->releaseNumber;
		    if (($num >= $startnum) && ($num <= $endnum))
		    {
			$romnum = sprintf('%04d', $num);
			$imgfile = 'imgs/0001-0250/'.$romnum.'.jpg';

			echo '<img src="' . $imgfile . '">';

		    }
		}
		echo '</p>';
	?>

Obviously, it doesnt work if the img number is higher than 250, and since it now goes up to 3000 I figure I need a script rather than just an if then else.

Link to comment
https://forums.phpfreaks.com/topic/145496-number-sequence/#findComment-763974
Share on other sites

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.