473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

order alfabetical many images

Hi all.

With this simple script I can see all my jpg in a web page..
but they are confused randomly in the page.

is there a way to put them alfabetically? from A to Z?
thanx

<?php
if ($handle = opendir('/cover')) {
while (false !== ($file = readdir($handle))) {
if (($file != "." && $file != "..")) {
echo " <img src=\"cover/$file\" alt=\"$file\" border=0> ";
}
}
closedir($handle);
}

?>

Oct 15 '05 #1
5 1688
Davide wrote:
Hi all.

With this simple script I can see all my jpg in a web page..
but they are confused randomly in the page. <?php
if ($handle = opendir('/cover')) {
while (false !== ($file = readdir($handle))) {
if (($file != "." && $file != "..")) {
echo " <img src=\"cover/$file\" alt=\"$file\" border=0> ";
}
}
closedir($handle);
}

?>


Put all the files in an array and sort it, then print

$files = array();

if (($file != "." && $file != "..")) {
$files[] = $file
}
all done:

asort($files);

for each($files as $file){
echo " <img src=\"cover/$file\" alt=\"$file\" border=0> ";
}
Oct 15 '05 #2
jamen wrote:
Put all the files in an array and sort it [...]
asort($files);


No need for asort(), just use sort(). See http://php.net/sort

--
E. Dronkert
Oct 15 '05 #3
I correct the script with yours suggests but seems doesn't work :(

<?php
if ($handle = opendir('./cover')) {
while (false !== ($file = readdir($handle))) {
$files = array($file);
if (($file != "." && $file != "..")) {
sort($files);
foreach($files as $file){
echo "<img src=\"cover/$file\" alt=\"$file\" border=0>";
}
}
}
closedir($handle);
}

?>

Oct 16 '05 #4
Davide wrote:
I correct the script with yours suggests but seems doesn't work :(

<?php
if ($handle = opendir('./cover')) {
while (false !== ($file = readdir($handle))) {
$files = array($file);
if (($file != "." && $file != "..")) {
sort($files);
foreach($files as $file){
echo "<img src=\"cover/$file\" alt=\"$file\" border=0>";
}
}
}
closedir($handle);
}

?>


if ($handle = opendir('./cover')) {
$files = array();

while (false !== ($file = readdir($handle))) {
if (($file != "." && $file != "..")) {
$files[] = $file;
}
}
closedir($handle);
sort($files);

foreach($files as $file){
echo "<img src=\"cover/$file\" alt=\"$file\" border=0>";
}

}
Oct 16 '05 #5
it works!

Thanx, really :)

Oct 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: robert | last post by:
hi! there's a line in my Javascript program that makes a change in the appearance of an area of the screen. it is a game program, so there are a cascade of changes after the user makes a move....
7
by: Lasse Vågsæther Karlsen | last post by:
I have a list of items and a "rule" for ordering them. Unfortunately, the rule is not complete so it won't define the correct order for any two items in that list. In other words, if I pick...
2
by: Jean Pierre Daviau | last post by:
When I have something like this in a js file. listeImg = new Array(); listeImg = new Image(w,h); listeImg.src = "centre1.jpg"; etc Are the images loaded after the page is loaded? In the same...
13
by: Kevin | last post by:
Hi, I have used ASP for years using MS Access and have used MSSQL quite a lot as well. I have never came across something like this before. MSSQL table names and types: ProductName nvarchar...
27
by: Chris Tomlinson | last post by:
Hi, is there any way to specify the sequence in which images load on a web page? More specifically, here is what we need to achieve: Image1 starts loading first and the browser does not...
0
by: PinkBishop | last post by:
In an asp.net application I have a datalist with a gridview inside a datalist template. The gridview is bound to the datalist select. When I run the following some records duplicate. But without...
1
by: aRTx | last post by:
<? /* Directory Listing Script - Version 2 ==================================== Script Author: Artani <artan_p@msn.com>. www.artxcenter.com REQUIREMENTS ============ This script requires...
1
by: TheLearner | last post by:
(Newbie) Greetings I am trying to create an Index page in Serif Webplus10. Regretfully the application doesn't have that feature I need. I would like to load 4/8 images ( picture +...
3
by: panteraboy | last post by:
Hi there acces gurus. I have a number of images in my form and i wish to place 1 image on top of another. Is there a way to order images such as in Microsoft word ie "Send to Back, Bring Forward". i...
2
by: kirstenkirsche | last post by:
Hi guys.... i know this question has been asked already and I found a few answers but it would be soo great if anyone could help me with this script, which just browses images on a webpage in an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.