Page 1 of 1

Get all records of the user in mysql table

Posted: 28 Jan 2017, 10:08
by JanMolendijk
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);
?>

Get all records of the user in mysql table

Posted: 28 Jan 2017, 15:40
by Admin
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;