I'm trying to add the data obtained from a select and order them to an array in PHP.
I want to accommodate the array in this way:
$array = array(noticias => array("1" => array ("titulo" => "Noticia 1", "autor" => "Pepe", "fecha" => "03/08/2018", "contenido" => "<b>Hola Mundo</b><br>")));
This is my code, so far I only get the last record in this way.
$sql = "SELECT * FROM noticias LIMIT 2";
$data=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($data)){
$datos_acomodados = array("titulo" => $row['titulo'], "autor" => $row['autor'], "fecha" => $row['fecha'], "contenido" => $row['contenido']);
//echo $row['titulo'];
//echo $row['autor'];
//echo $row['fecha'];
//echo $row['contenido'];
}
mysqli_close($conn);
I have this doubt and also in the way I am doing it.