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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.