Essentially, I built a small text chat type application for me and my friends and now the messages seem to be getting kind of long on the page so I thought it be better if I could just display the latest 10 or 20 messages or so.
That said, I tried a for loop like so:
$row = mysqli_num_rows($dbqDoIt4_mssgs);
for($i = 0; $i<5; $i++){
if($row[$i]<5){
echo '<div class="holdChat"><span class="orangeBigger">' . strtoupper($row['user']). '</span>' . ' ' . '<span class="txtSaid">said:</span> ' . '<span style="color:#171717;">' . $row['mssg'] . '</span>' . '</div><br/>';
}
}
This last part of the code is kind of long, but essentially it holds the CSS classes, etc. for a gray box with the database text in it.
It now does display five rows (or however many I tell it to). I get no errors for the code or PHP, but the message itself from the database does not show, so all I get are empty gray boxes on the HTML where the text is supposed to be.
I’m assuming, because maybe I’m referencing the $row as $row[i], that it’s not directly picking up the message(?)
(I am building a small application to teach myself PHP.)
I would do something like this: