473,387 Members | 1,863 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,387 software developers and data experts.

Files being read in (seemingly) random order

18
hi, i'm using opendir( ) to create resource to a directory, and readdir( ) thereon to read the files one by one. I then add the file info into a database, and they are listed back in the very order that they were added. This order is a must-have.

But because of some odd reason, the files are not being added either
- alphabetically
- date and time of uploading

This is defeating my purpose. Moreover, it seems completely random. Why is this so? Is it something with Apache. Or does it depend on the OS my webhost is running on? I'm using apache on windows, and smething like this never occurred on my side.
May 3 '07 #1
4 1469
code green
1,726 Expert 1GB
The order they are added to the database is meaningless to the database. You use ORDER BY to read the data back.
May 4 '07 #2
guile
18
The order they are added to the database is meaningless to the database. You use ORDER BY to read the data back.
using ORDER BY is the recommended thing, but what do I order by?
If I order by the file name, then things might go wrong as file uploads later might not exactly follow the same naming scheme but would be shown first based on their name.
If I order by the file title/caption, then things go absolutely wrong.

So only way for me was ordering them by the way they are added, which I expected to follow some alphabetical order, or the order in which files are uploaded.

Any idea why its breaking on my serve while working fine on my side (WAMP)?
May 4 '07 #3
pbmods
5,821 Expert 4TB
Why not use a serial on the table that stores the images?

E.g.,

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `MyFiles`(
  2.  `fileid` serial,
  3.  `dirid` bigint(20) unsigned not null,
  4.  `filename` varchar(256) not null,
  5.  UNIQUE KEY `dirFile(`dirid`, `filename`)
  6. );
  7.  
or

Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE `MyFiles` ADD `fileid` serial FIRST;
  2.  
'serial' is an alias for 'bigint(20) unsigned not null primary key auto_increment'.

By default, MySQL will return your results ordered by the primary key, which would represent the order they were added to the table.
May 4 '07 #4
You can order by any field you want, number, alphabetical, whatever.
You don't have to add another field.
You can also specify how you want the field sorted with asc & desc.
Steph
Aug 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Laphan | last post by:
Hi All I know this is my 2nd (and final) cross-post, but which NG should I use for the below. I want to create a game that queries and updates text and numeric stats on a regular basis, so...
22
by: kalio80 | last post by:
Hi everyone I am trying to create a file that converts text files from unix to windows and windows to unix I understand the general concept of it as unix uses line feed LF Windows uses CRLF...
1
by: ketema | last post by:
Hello, I was wondering if someone could help me with a function I am trying to write. The purpose of the function is to read in text from a file in the following format: FIRSTNAME LASTNAME...
1
by: Patrick | last post by:
Hi, This post is the 'sequel' ;) of the "Data Oriented vs Object Oriented Design" post, but it can be read and treated apart from that one. I will just quote the beginning of my previous message...
5
by: Bas Hendriks | last post by:
Has anyone any idea how asp.net find it's files back after compiling them to the temporary asp.net directory? I found on numerous webpages that the directorynames are chosen random but cannot find...
4
by: Khoa Nguyen | last post by:
Hi, I have a requirement to process all files in a directory in chronological order. The os.listdir() function, however, lists the files in random order. Is there a similar function in Python...
5
by: jason735 | last post by:
Hi, I've got the following problem. I have to sort x*y elements which are in one file. I can use only an array for x elements and floor tmp files which can be read only forward. Thanks for...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
1
by: =?utf-8?q?C=C3=A9dric_Lucantis?= | last post by:
Le Wednesday 02 July 2008 01:16:30 Ben Keshet, vous avez écrit : If the file you're reading is not too big, you can use file.readlines() which read all the files and returns its content as a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.