Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

mysqli - PHP mySQLi_fetch_all: iterate through each row

I am retrieving the rows of my query as such:

$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);

How can I do:

(PSEUDO CODE)
for each row in rows
  echo row

I can just "echo $rows" but that doesn't allow me to go through each row on a separate paragraph.

As a second question, how can I go through each column of a row:

(PSEUDO CODE)
for each row in rows
  for each column in row
    echo column
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You pseudo code is all fine.. you just need to turn it into PHP....

Answer to first question:

// Loop through each row and print it
foreach( $rows as $row ):
   print_r( $row )
endforeach;

Second question.. something like:

foreach( $rows as $row ):
   foreach( $row as $col ):
      echo $col;
   endforeach;    
endforeach;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...