after each result, but not the last result? This is my incomplete code: while($row = $db->fetch_array($query)) { echo $row['row...">

How to add <br/"> after each result, but not the last result?

This is my incomplete code:

while($row = $db->fetch_array($query)) { echo $row['row_name']; } 

How can I do this to add a break tag after each result, but not the last result?

+4
source share
3 answers

Put the output in an array, then attach the array to implode :

 $rows = array(); while($row = $db->fetch_array($query)) { $rows[] = $row['row_name']; } echo implode('<br/>', $rows); 
+16
source

Can you do this. No arrays or counters.

 if($row = $db->fetch_array($query)) { do { echo $row['row_name'] } while($row = $db->fetch_array($query) && print("<br />")); } 
+6
source
 for ($idx = 0; $row = $db->fetch_array($query); $idx++) { if ($idx > 0) { echo "<br/>"; } echo $row['row_name']; } 
+2
source

Source: https://habr.com/ru/post/1338183/


All Articles