html - Seprate values from mysql column data with php
I want to echo a column value, which is working fine, But I want to break the line when there is a comma came in, so I want to get each value in one line. ipd_medicine_name column has multiple values in it, which are separated by ' , ' (comma)
$records = mysqli_query($conn, "SELECT ipd_medicine_name FROM `ipd_patients` WHERE ipd_patientid = ".$_GET['ipd_patientid']." ");
while($data = mysqli_fetch_array($records))
{
echo " <p>"$data['ipd_medicine_name']."</p> ";
}
?>
Answer
Solution:
This should work for you:
echo '<p>' . str_replace(',', '<br />', $data['ipd_medicine_name']) . '</p>';
Source