0
$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)
FROM 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!  the problem when there is no table treatment is empty, comma will still there
consultation follow_up acid peel dermal

i heard i can use implode. how do i implement it? EXPECTED RESULT:

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

1 Answer 1

2

You can put all values in an array and 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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.