Get all records of the user in mysql table

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts:282
Location:Holland Rotterdam

Get all records of the user in mysql table

My next problem when i use this code i getting one record from user='anonymous@hotmail.com'
but i would like to have all the records what is posted to user='anonymous@hotmail.com'.

Code: Select all

<?php
include('../connection.php');

$sql=mysqli_query($conn,"SELECT * FROM `notice` WHERE user='anonymous@hotmail.com' ");
$users=mysqli_fetch_assoc($sql);
?>

Admin Posts:805
Hello,
You have to use a while() loop to traverse the rows returned in the result set.

Code: Select all

$sql=mysqli_query($conn,"SELECT * FROM `notice` WHERE user='anonymous@hotmail.com' ");

$rehtm='';
// if the $sql contains at least one row
if(mysqli_num_rows($sql) >0){
  //get rows data
  while($row = mysqli_fetch_assoc($sql)){
    $rehtm .='<br>'. $row['col1_name'] .' -- '. $row['col2_name'];
  }
}
else {
  $rehtm .='0 results';
}

echo $rehtm;