0

I have a problem. My first code (MYSQL) is giving me the latest 5 rows from the table chat. My second code (MYSQLi) doesn't return anything, leaves the page blanc, and gives me no error messages.

Code 1:

$messages = array ();
$sql = mysql_query("select * from users ORDER BY pid DESC LIMIT 5");
while( $results = mysql_fetch_assoc($sql) )
{
    array_unshift( $messages, $results);
}

Code 2:

$messages = array ();
$sql = mysqli_query($con, "select * from users ORDER BY pid DESC LIMIT 5");
while( $results = mysqli_fetch_assoc($sql) )
{
    array_unshift( $messages, $results);
}

I think the code is fully correct. But still, as I said, I don't get any output, just a blanc page. Can anyone help me? I don't like PDO, so looking for procedural options.

droopsnoot
  • 931
  • 1
  • 7
  • 11
Banzouzi
  • 11
  • 5
  • You need to learn about the very important concept of error reporting. No page would give you an error message unless you'd explicitly ask it to – Your Common Sense Dec 22 '20 at 12:44
  • Have you checked that the database connection `$con` is good? Did you check for errors when you created the connection? There's nothing in the code to produce any output, so I'm not sure why you are surprised you get a blank page. – droopsnoot Dec 22 '20 at 12:46
  • You can use PDO either with procedural or OO techniques by the way - preferring procedural is not a reason to avoid PDO. – droopsnoot Dec 22 '20 at 12:46
  • Did you check to see whether the query actually executed properly? What is in `$sql` when you display it while you're debugging? – droopsnoot Dec 22 '20 at 12:47

0 Answers0