0

I have a table in a database that has multiple fields with an ID. I want to fetch all rows with ID=1 (for example ID=1 has 3 rows in the table). I have written a query to fetch the rows with ID=1 from the db, but this query only fetches the first row. I want to fetch all rows of the ID=1.

How i can fetch all rows of ID=1?

My PHP Code:

 $conn = mysqli_connect('localhost', 'root', '', 'win');
 $query = "SELECT * FROM lights WHERE id='1'";
 $result = mysqli_query($conn, $query);
 $row = mysqli_fetch_assoc($result);
 print_r($row);
?>```
1
  • Do you really use all the fields from the "lights" table? If you don't, only select the fields that you'll actually use Commented Mar 29, 2019 at 20:49

1 Answer 1

2

You need to loop through mysqli_fetch_assoc($result)

while ($row = mysqli_fetch_assoc($result)) { //Goes through each row of the query
    print_r($row); //A row from the table
}

Source: mysqli_result

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.