?
Solved

Limit Result to one occurance of a name MYSQL PHP

Posted on 2010-01-13
3
Medium Priority
?
175 Views
Last Modified: 2013-12-12
Hello,

I need to select some calling rates to display on another website all works well but the issue I have is that there are many duplicates in the database due to there being a number of dial prefixes, all I want to show how ever it the destination (Country Name) and the Sell Pirce per minute.

Code attached that works.... to show all

So result at the moment is displayed for example;

Afghanistan 0.25000
Afghanistan 0.25000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Afghanistan Mobile 0.28000
Albania 0.05000
Albania 0.05000
Albania Mobile 0.35000
Albania Mobile 0.35000
Albania Mobile 0.35000
Albania Mobile 0.35000
Albania Mobile 0.35000
Albania Mobile 0.35000


but I want it to disaply like this,

Afghanistan 0.25000
Afghanistan Mobile 0.28000
Albania 0.05000
Albania Mobile 0.35000

How can I do this?

<?php
$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = 'database';
mysql_select_db($dbname);

$sql = 'SELECT cc_prefix.destination, cc_ratecard.rateinitial FROM cc_ratecard, cc_prefix WHERE cc_ratecard.destination = cc_prefix.prefix ORDER BY cc_prefix.destination ASC';

$result = mysql_query ($sql)  or die ('Cannot Select Error : ' . mysql_error());

while($row = mysql_fetch_array($result))  {
  echo $row['destination'];
 echo " ";
echo $row['rateinitial'];
  echo "<br />";
}

 ?>

Open in new window

0
Comment
Question by:AUCKLANDIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
ludofulop earned 2000 total points
ID: 26302590
hi, use DISTINCT to select unique column values:

$sql = 'SELECT DISTINCT cc_prefix.destination, cc_ratecard.rateinitial FROM cc_ratecard, cc_prefix WHERE cc_ratecard.destination = cc_prefix.prefix ORDER BY cc_prefix.destination ASC';
0
 
LVL 1

Author Comment

by:AUCKLANDIT
ID: 26302603
thanks for the quick reply of course - too much coffee too late can't think!
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 26302606
this should do:

$sql = 'SELECT cc_prefix.destination, cc_ratecard.rateinitial FROM cc_ratecard, cc_prefix WHERE cc_ratecard.destination = cc_prefix.prefix GROUP BY  cc_prefix.destination ORDER BY cc_prefix.destination ASC';
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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