I have a nested list that will show customers and their phone numbers like this:
Jason
555 111-1111
555 222-2222
Kristen
555 333-3333
John
555 444-4444
555 555-5555
555 656-6666
I'm having trouble adding their emails, though. This code just duplicates the email under each phone number, but I need the phone numbers and emails to be grouped under each customer like:
Jason
555 111-1111
555 222-2222
[email protected]
[email protected]
Kristen
555 333-3333
[email protected]
[email protected]
[email protected]
John
555 444-4444
555 555-5555
555 656-6666
[email protected]
PHP CODE:
<?php
$result = mysqli_query($dbc,"
SELECT
fname,
phone,
email
FROM
customer,
phone,
email,
customer_phone,
customer_email
WHERE
customer.id=customer_phone.customer_id
AND
phone.id=customer_phone.phone_id
AND
customer.id=customer_email.customer_id
AND
email.id=customer_email.email_id
order by fname
");
$oldname = null;
while($row = mysqli_fetch_array($result))
{
if($oldname != $row['fname'])
{
echo "<h3>".$row['fname']."</h3>";
$oldname = $row['fname'];
}
echo "<p>".$row['phone']."</p>";
echo "<p>".$row['email']."</p>";
}
?>