Jump to content

PHP & MySQL Output Question


chordsoflife

Recommended Posts

I'm outputting address and phone number info from a database. In one situation, one person has two phone numbers. The result of outputting is that the person with two phone numbers is displayed twice, each with one number. I want the person to be displayed once, with both numbers. Is there a simple way to do that? Here's the code:

 

$people = mysql_query("SELECT pkPersonID, fldFirstName, fldLastName, fldNumber, fldPhoneType, fldBirthday FROM tblPerson, tblPhone, tblPersonPhone WHERE pkPersonID=fkPersonID AND pkPhoneID=fkPhoneID ORDER BY fldFirstName, fldLastName;", $conn);

while($person = mysql_fetch_array($people, MYSQL_ASSOC)){


?>

	<div class="entry">		
		<h2><?=ucwords($person[fldFirstName]);?> <?=ucwords($person[fldLastName]);?></h2>
		<p class="byline">DOB: <?=$person[fldBirthday];?></p>
		<p><?=formatPhoneNumber($person[fldNumber]);?> | <?=ucwords($person[fldPhoneType]);?></p>
		<p class="entryMenu"><a href="">Add A Number</a> | <a href="">Delete Entry</a></p>
	</div>

<?

}

Link to comment
https://forums.phpfreaks.com/topic/147405-php-mysql-output-question/
Share on other sites

I appreciate the help. Here's the create SQL for the tables I'm using:

 

create table tblPerson (pkPersonID int primary key auto_increment,fldFirstName varchar(15),fldLastName varchar(15),fldBirthday date());
create table tblPhone (pkPhoneID int primary key auto_increment,fldNumber int);
create table tblPersonPhone (fkPersonID int,fkPhoneID int,fldPhoneType varchar(15),fldPhoneOrder int);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.