Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/04/2010, 17:21
nanoweb
 
Fecha de Ingreso: septiembre-2006
Mensajes: 10
Antigüedad: 17 años, 7 meses
Puntos: 0
Ordenar datos en PHP

Estimados,

Tengo una aplicación en Flash+PHP (editor de NOTICIAS). El PHP lee las noticias de un txt (noticias1.txt) y las muestra en el archivo swf.
Actualmente las noticias me las muestra en orden ascendente, es decir, se ve primero la noticia antigua y debajo la mas nueva...

La idea es ordenarlas al contrario: que se muestre primero la noticia mas reciente y debajo d ésta las más antiguas.
El php es el siguiente...

============ C O D I GO =======

<?php
error_reporting(0);
$filename="noticias1.txt"; //sets file to edit
$readfh = fopen($filename, "a"); //File handle for $filename
$contents = fread($readfh, filesize($filename)); //Reads file, through handle $readfh.
?>
<html>
<head>
<title>Gestor de Contenidos</title>
</head><div align="center">
<body>
<h3>Gestor de Contenidos - NOTICIAS - Energía Eólica</h3>

<?php
if(isset($_POST['submit'])) { //if submit was pressed
$writefh = fopen($filename, "a"); //File handle for $filename

if(get_magic_quotes_gpc()){
$newcontents=stripslashes($_POST['editcontents']);
} //strips unneeded backspaces by magicquotes
else{
$newcontents = $_POST['editcontents'];
}
//NEXT 3 LINES ARE THE PROBLEM SPOT:
fwrite($writefh, $newcontents); //Saves changes
rewind($readfh); //resets cursor in file
$contents = fread($readfh, filesize($filename)); //Updates $contents
echo("La noticia se agregó correctamente....<br/>\n");
fclose($writefh);
}
?>
Pega aquí el código HTML generado en el EDITOR de TEXTO:
<form method="post" action="<? echo($PHP_SELF); ?>">
<textarea name="editcontents" style="overflow:auto;width:500px; height:300px;"><? echo($contents);?></textarea>
<br />
<input type="submit" name="submit" value="actualizar texto" />

<?php fclose($readfh); ?>
</form>
</body>
</div>
</html>

============== F I N =========

¿Qué debería modificar para que se muestren las noticias en el orden deseado...?

Desde ya muchas gracias...