0

as I order the result to alphabetical order?

need it to read the directory and add the files in alphabetical order in mysql ...

$path = "artes110/$grupo";
$diretorio = opendir($path);

while ($arquivo = readdir($diretorio)){
if ($file != '.' && $file != '..')
{
$arquivo = utf8_encode($arquivo);
$arquivo = html_entity_decode($arquivo);
$query = mysql_query("INSERT INTO artes101 (imagem, data, texto, layout, grupo) VALUES ('$path/$arquivo', '$data2', '$texto', 'peq', '$grupo')") or die(mysql_error());

}
}
Alan PS
  • 197
  • 2
  • 12
  • 3
    Even if you insert them in alphabetical order, mysql might not store them in that order. The beauty of sql is that you get the data out of the database in an order you specify. So if you want to display them in a particular order you just specify `order by` in any query of that data after it is inserted. – MrVimes Jan 27 '14 at 13:23
  • the problem is that I need to leave them in the order that the id is auto-increment and primary key in entering data. – Alan PS Jan 27 '14 at 13:28
  • http://stackoverflow.com/questions/541510/php-readdir-not-returning-files-in-alphabetical-order – MrVimes Jan 27 '14 at 13:32

1 Answers1

0

In mysql you can add them in any order and then get them ordered by adding an order by clause in your SQL code.

SELECT * FROM artes101 ORDER BY imagem DESC;

You can change imagen to whatever field you want them sorted by, and can change the direction of the order by changing the DESC to ASC

gpopoteur
  • 1,509
  • 10
  • 18