Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mysql

This is my partial code:

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

How can I make it so it will add a break tag after each result, but not the last result?

like image 765
Spencer Avatar asked Nov 29 '22 10:11

Spencer


1 Answers

Put the output into an array, then join the array with implode:

$rows = array();
while($row = $db->fetch_array($query))
{
     $rows[] = $row['row_name'];
}
echo implode('<br/>', $rows);
like image 185
lonesomeday Avatar answered Dec 01 '22 00:12

lonesomeday