I am making a private message system and I'm using the mysqli_fetch()
function in a while
statement to return all the rows associated with the query. However, PHP only returns the last row in MYSQL.
Here is my code:
<?php
$Connect = new mysqli("localhost", "root", "", "Data");
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$Val = $_POST['ID'];
$Get = 'SELECT * FROM CMessages WHERE PID="'.$Val.'"';
$Username = $_SESSION['Username'];
$Admin = $_SESSION['Admin'];
if($Result = $Connect->query($Get))
{
while($Row = $Result->fetch_assoc())
{
$User = $Row['Username'];
$Msg = $Row['Msg'];
$Date = $Row['Date'];
$ID = $Row['ID'];
if($User == $Username)
{
$MText['T'] = '<div id="Msg">' . $User . ' : ' . $Msg . ' - ' . $Date .' - <a class="TLink" href="MDelete.php?ID='.$ID.'">Delete</a></div>';
}
elseif(isset($Admin))
{
$MText['T'] = '<div id="Msg">' . $User . ' : ' . $Msg . ' - ' . $Date .' - <a class="TLink" href="MDelete.php?ID='.$ID.'">Delete</a></div>';
}
else
{
$MText['T'] = '<div id="Msg">' . $User . ' : ' . $Msg . ' - ' . $Date .'</div>';
}
}
}
echo json_encode($MText);
?>