[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


If duplicate entry in database, only show one

Posted on 2008-11-06
Medium Priority
Last Modified: 2013-12-13

The code below I am using to display information in a database.  If there is a duplicate entry like say same first and last name (firstname/lastname fields), what do I need to add so only one is displayed?

Thank you
/*** Set rotation of row colors, first a counter ***/
/*** the CSS class names ***/
$colors = array('dark', 'light');
// Connect to database
		$dbhost = 'localhost';
		$dbuser = 'xxx';
		$dbpass = 'xxx';
		$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
		$dbname = 'tt-marketing';
		mysql_select_db($dbname, $conn);
		$result = mysql_query("SELECT * FROM customers ORDER BY country");
		if( mysql_num_rows($result) > 0 )
			while($row = mysql_fetch_array($result))
		foreach($data as $v){
		echo "<TR class='gridview_".$colors[$i++ % 2]."'><TD>".$v['country']."</TD><TD>".$v['firstname']."</TD><TD>".$v['lastname']."</TD><TD>".$v['company']."</td><td>".$v['street']."</TD><TD>".$v['city']."</TD><TD>".$v['state']."</TD><TD>".$v['zip']."</TD><TD><a class=\"normal\" href='mailto:".$v['email']."'>".$v['email']."</a></TD><TD>".$v['phone']."</TD><TD>".$v['optin']."</TD></TR>";

Open in new window

Question by:vrmetro
  • 2
LVL 17

Expert Comment

ID: 22900601
change line 14 to:

$result = mysql_query("SELECT * FROM customers ORDER BY country limit 1");

Open in new window

LVL 17

Assisted Solution

nanharbison earned 400 total points
ID: 22900613
wait, do you mean you want to show a lot of rows in the table, but only one if the same first and last names are the same?
LVL 27

Accepted Solution

Cornelia Yoder earned 1600 total points
ID: 22900681
SELECT * FROM customers GROUP BY LastName, FirstName ORDER BY country

Author Closing Comment

ID: 31514175
Thank you

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question