Hola, tengo una pagina para publicar eventos hecha con php y sin base de datos, en lugar de esta, utilizo un archivo formato txt. Al publicar un nuevo evento este aparece en la pagina hasta abajo de todos los eventos posteados anteriormente haciendo que el usuario tengo que llegar hasta abajo para ver los nuevos eventos, ¿Como hago para que los eventos vallan apareciendo hasta arriba? ¿Que le cambio a mi codigo:
Código PHP:
<?php
$file_name = "events.txt";
$post_sep = "<###>";
$info_sep = "----";
class writePosts {
function inputPost($inputRandomId, $eventName, $startDate, $selectTime, $eventDescription, $eventLocation, $eventCreator) {
global $file_name, $post_sep, $info_sep;
$date = time();
$self = $_SERVER['PHP_SELF'];
$inputRandomId = $inputRandomId;
$eventName = $eventName;
$startDate = $startDate;
$selectTime = $selectTime;
$eventDescription = $eventDescription;
$eventLocation = $eventLocation;
$eventCreator = $eventCreator;
$fh = fopen($file_name, "r+");
fread($fh, filesize($file_name));
fwrite($fh, $inputRandomId.$info_sep.$eventName.$info_sep.$startDate.$info_sep.$selectTime.$info_sep.$eventDescription.$info_sep.$eventLocation.$info_sep.$eventCreator.$post_sep);
fclose($fh);
echo "<script>window.location = '$self'; </script>";
}
function getPost(){
if (isset ($_POST['inputRandomId']) && isset ($_POST['eventName']) && isset ($_POST['startDate']) && isset ($_POST['selectTime']) && isset ($_POST['eventDescription']) && isset ($_POST['eventLocation']) && isset ($_POST['eventCreator'])) {
$this->inputPost($_POST[inputRandomId], $_POST[eventName], $_POST[startDate], $_POST[selectTime], $_POST[eventDescription], $_POST[eventLocation], $_POST[eventCreator]);
}
}
}
class readPosts{
function readAll(){
global $file_name, $post_sep, $info_sep;
$fh = fopen($file_name, "r");
$all = fread($fh, filesize($file_name));
fclose($fh);
$each = explode($post_sep, $all);
$i = 0;
$counteach = count($each);
while($i < $counteach - 1){
$post_info = explode($info_sep, $each[$i]);
$this->outPost($post_info[0], $post_info[1], $post_info[2], $post_info[3], $post_info[4], $post_info[5], $post_info[6]);
$i++;
}
}
function outPost($inputRandomId, $eventName, $startDate, $selectTime, $eventDescription, $eventLocation, $eventCreator){
$inputRandomId = $inputRandomId;
$eventName = $eventName;
$startDate = $startDate;
$selectTime = $selectTime;
$eventDescription = $eventDescription;
$eventLocation = $eventLocation;
$eventCreator = $eventCreator;
echo "<div class=\"newEvent\" id=\"event$inputRandomId\"><span class=\"newEventName\">$eventName</span><br><span class=\"newEventDate\">Inicia: $startDate a las $selectTime</span><br><span class=\"newEventLocation\">Lugar: $eventLocation</span><br><span class=\"newEventDescription\">$eventDescription</span><br><span class=\"newEventCreator\">Creado por: $eventCreator</span><br><a id=\"display$inputRandomId\" class=\"displayFBcomments\" href=\"javascript:;\" onclick=\"commentLink('$inputRandomId','none','block')\">Ver comentarios del evento</a><a id=\"hidde$inputRandomId\" class=\"hiddeFBcomments\" href=\"javascript:;\" onclick=\"commentLink('$inputRandomId','block','none')\">Ocultar comentarios</a><br><div class=\"FBcomments\" id=\"comments$inputRandomId\"><fb:comments xid=\"$inputRandomId\" numposts=\"20\" width=\"600\" simple=\"true\"></fb:comments></div><br><div class=\"hrEndEvent\"></div></div>";
}
}
$write = new writePosts;
$read = new readPosts;
$write->getPost();
?>