please help i am making a message box which allows user to send message to each which will be stored in database. my problem is while inserting new message it successfully inserts to my database.but while printing the values from my database it prints the previously inserted message first..but i need to be print newly added message.
<?php
include 'connection.php';
$result=mysqli_query($con,"SELECT * FROM MESSAGES WHERE ID='9996565'");
while($row=mysqli_fetch_array($result))
{
echo $row['message'];
}
?>
while printing $row['message'] i need to print recently added message first pls help me!!!
You can control this using ORDER BY
clause in your SQL query:
$result = mysqli_query($con, "SELECT * FROM MESSAGES ORDER BY ID DESC LIMIT 1");
The above example will fetch all the entries in reverse order, and echo $row['message'];
message would display the last entry first. You can change the query according to your needs, but that's what you basically need.