Reputation: 151
I am trying to loop through my database and then shown all user names. Unfortunately I have tried many different ways but can not get it to work. I am currently trying this
<?php
$result= mysqli_query("SELECT * FROM users");
while($userRow = mysqli_fetch_array($result)){
echo $userRow['user_name'];
}
?>
The issue is that I am getting this error and can not work out how to get this working. Warning: mysqli_query() expects at least 2 parameters, 1 given
I am able to show a single row using
<?php print($userRow['user_name']); ?>
But I can not work out how to loop through every user in my 'user' table
Upvotes: 0
Views: 45
Reputation: 4038
you have first create link like this
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
and then you have use the link to query the database like this
$result= mysqli_query($link, "SELECT * FROM users");
Upvotes: 0
Reputation: 18601
You have to pass first argument as Connection object you have to pass in mysqli_query()
function.
mysqli_query($con,"SELECT * FROM users");
Upvotes: 1