Log in

View Full Version : [+rep] PHP Help



Mr-Trainor
09-03-2013, 06:56 PM
Ok, so earlier this year I made this page (with the help of a tutorial I found online and just playing around with it and editing it) and basically what I'm trying to do is make a page where you can find new catalogue icons uploaded to Habbo. So here's what it is at the moment: (or click here to see how it looks, i.e. the layout of it (http://mr-trainor.net/rv/testtttt.php))


<?php


$handle = opendir(dirname(realpath(__FILE__)).'/directory/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
echo '<img src="http://images.habbo.com/c_images/catalogue/'.$file.'" border="0" /> '.$file.'<br />';
}
}
?>


But what I want to do is order them so that they show up in order of their number, i.e. 1,2,3... 178,179 and so on. So if anyone can help with that, it'd be much appreciated :D! I have very little knowledge of PHP and everything I've tried has failed :(.

Chippiewill
09-03-2013, 07:59 PM
Rather than echoing them add them to an array by their number and then iterate through the array.

Mr-Trainor
10-03-2013, 10:31 PM
Rather than echoing them add them to an array by their number and then iterate through the array.
Thanks, I'll play around with it tomorrow and see if I can get it to work :).

Mr-Trainor
16-03-2013, 11:05 AM
I got rid of what I had before, and just came up with this:


<?php

$number=array("1","2","3","4","5","6","7","8","9","10");
$arrlength=count($number);
for($x=0;$x<$arrlength;$x++)
{
echo '<img src="http://images.habbo.com/c_images/catalogue/icon_' . $number[$x] . '.png" border="0" /> icon_' . $number[$x] . '.png<br />';
}

?>


Is there a quicker way to add all numbers 1-200 :P?

---------- Post added 16-03-2013 at 11:13 AM ----------

Ok nevermind, I managed to do it like this:


<?php

foreach (range(1, 200) as $number) {
echo '<img src="http://images.habbo.com/c_images/catalogue/icon_' . $number . '.png" border="0" /> icon_' . $number . '.png<br />';
}

?>

Jia
18-03-2013, 10:57 AM
<?php
for( $i = 1; $i <= 200; $i++ ) {
echo "<img src=\"http://images.habbo.com/c_images/catalogue/icon_{$i}.png\" border=\"0\" /> icon_{$i}.png<br />";
}
?>

I think you should be able to understand why. It's much simpler this way.
@Mr-Trainor

Want to hide these adverts? Register an account for free!