php - String from Mysql results -
im grabbing voltages database , displaying them on page code below:
$separator = ''; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $volt = $separator.$row['volt']; $separator = ','; echo $volt; } }
this outputs following: 12.34,12.45,13.01 etc how call data outside while loop?
if echo $volt outside 1 value ,12.34 example not full string?
save data array :
$volts = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $volts[] = $row['volt']; } } echo implode(',',$volts);
i used implode() join elements of array
Comments
Post a Comment