Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 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 Reply

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...