Link to home
Start Free TrialLog in
Avatar of AUCKLANDIT
AUCKLANDITFlag for New Zealand

asked on

Limit Result to one occurance of a name MYSQL PHP

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

ASKER CERTIFIED SOLUTION
Avatar of ludofulop
ludofulop

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AUCKLANDIT

ASKER

thanks for the quick reply of course - too much coffee too late can't think!
Avatar of Guy Hengel [angelIII / a3]
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';