<?php
$queryuser = "SELECT id, email, firstname, lastname, address, city, country FROM users WHERE role = 'client'";
$resultuser = $connection->query($queryuser);
if ($resultuser->num_rows > 0)
{
// output data of each row
while ($rowuser = $resultuser->fetch_assoc())
{
$id_user = $rowuser['id'];
$firstname = $rowuser['firstname'];
$lasttname = $rowuser['lastname'];
$email = $rowuser['email'];
$phone = $rowuser['phone'];
$city = $rowuser['city'];
$state = $rowuser['state'];
$address = $rowuser['address'];
?>
Asked
Active
Viewed 1,100 times
-3

Pinke Helga
- 6,378
- 2
- 22
- 42

Micheal Samson
- 1
- 2
-
2What is your question? – markmoxx Jan 17 '19 at 16:37
-
1Your query failed. Check for [mysqli errors](http://php.net/manual/en/mysqli.error.php) to find out why. – aynber Jan 17 '19 at 16:38
-
1There's a really big, common, canonical duplicate for this ... if only SO's search was a little better I'd find it in a couple of seconds... – CD001 Jan 17 '19 at 16:41
-
1Welcome to SO. Please read [ask] and improve your question using the [edit](https://stackoverflow.com/posts/54240336/edit) link below the question. – Pinke Helga Jan 17 '19 at 16:41
-
where you got `$connection`? – A l w a y s S u n n y Jan 17 '19 at 16:46
1 Answers
0
Perhaps you've copied code from this page https://www.w3schools.com/php/php_mysql_select.asp
- Please understand code line by line first. You have not define
$connection
variable in your code (may be it is a intentional approach for security). - Your notice saying that you are trying to get
num_rows
property from the object$resultuser
but in this query$resultuser
is not a object due to any error/faults of your query because query() returns FALSE on failure and object on success. - To confirm, you can check your result set by using var_dump();
- Please replace this line if $resultuser->num_rows > 0 with
(!empty($resultuser->num_rows) && ($resultuser->num_rows > 0)))

johirpro
- 509
- 4
- 16