0

I have a database which lists all of my users and associated with each user is their team. I have the following query

SELECT * FROM users WHERE team = 'red'

which will obviously return more than one row from the database. It seems that the mysqli_fetch_all function is ideal for handling these results but I'm not sure what that's going to return to me.

Will I get a two dimensional array such as $users[user][details] or something else entirely?

aksu
  • 5,221
  • 5
  • 24
  • 39
Nick Chapman
  • 4,402
  • 1
  • 27
  • 41
  • @AlexMorrise Seems similar but I'm not totally sure I understand the question and answers there. If you see my comment on the answer below, can you explain that to me? – Nick Chapman Dec 17 '13 at 17:56

1 Answers1

0

Use a while loop.

For instance:

$query = mysqli_query($conn, "SELECT * FROM `users` WHERE `team` = 'red'");
while($row = mysqli_fetch_all($query)){
   //Process each row
   echo $row["name"];
}

Untested but it should be what you're looking for.

Devyn
  • 219
  • 1
  • 2
  • 15
  • I see this method a lot, can you elaborate on what that is actually doing? I'm confused as to what is being iterated over? How does it know I want the next row every time it runs that loop? – Nick Chapman Dec 17 '13 at 17:53
  • 1
    Sorry for the late reply. Basically it fetches all rows from the database where the team is equal to red. Then it iterates through each query using $row as the variable for every row. Inside the loop is where you get the information from the specific row that it's currently on. Once that code inside the loop is complete it will assign the next row to $row and do it again until there are none left. I hope I answered your question properly. – Devyn Jan 10 '14 at 19:56