0

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

1
  • 1
    give connection object as a first parameter Commented Dec 10, 2015 at 6:48

2 Answers 2

1

You have to pass first argument as Connection object you have to pass in mysqli_query() function.

mysqli_query($con,"SELECT * FROM users");

Reference

Sign up to request clarification or add additional context in comments.

Comments

0

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.