Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Limit Result to one occurance of a name MYSQL PHP

Posted on 2010-01-13
3
Medium Priority
?
178 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
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

572 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