php - how to use mysql implode while loop -


$mysqli->query("select b.t_follow_up, b.t_consultation, b.t_acid_peel, b.t_wrinkle_name, b.t_dermal_name, b.status, b.date_book, b.min_spent, b.b_ref, m.f_name, m.l_name, d.doctor_name, min(t.times) bookslot b left join timeslot t on b.id_timeslot = t.id_timeslot left join member m on b.id_member = m.id_member left join doctor d on b.id_doctor = d.id_doctor  while($r = $q->fetch_array(mysqli_assoc)) :     echo '. $r['t_consultation'] . ' ' . $r['t_follow_up'] . ' ' . $r['t_acid_peel'] . ' ' . $r['t_dermal_name'] . ' '  . $r['t_wrinkle_name'] '; endwhile; 

while loop result:

i can put comma in while loop manually!  problem when there no table treatment empty, comma still there consultation follow_up acid peel dermal 

i heard can use implode. how implement it? expected result:

if echoing treatments: consultation, acid peel, wrinkle name, dermal name 

you can put values in array , remove empty elements:

function isnotempty($element) {     return strlen($element) > 0; }  while($r = $q->fetch_array(mysqli_assoc)) :     $arr = array($r['t_consultation'], $r['t_follow_up'], $r['t_acid_peel'], $r['t_dermal_name'], $r['t_wrinkle_name']);     echo implode(', ', array_filter($arr, 'isnotempty')); endwhile; 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -