If duplicate entry in database, only show one

Posted on 2008-11-06
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
    LVL 17

    Expert Comment

    change line 14 to:

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

    Open in new window

    LVL 17

    Assisted Solution

    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

    SELECT * FROM customers GROUP BY LastName, FirstName ORDER BY country

    Author Closing Comment

    Thank you

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    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…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now