Jump to content

[SOLVED] list users based on country


jakebur01

Recommended Posts

How can I select the unique values in a column? For instance: If I have United States on 4 rows, Peru on 3, and Argentina on 5.......... but only want to select them once and order them.... like  Argentina, Peru, United States.

 

I am trying to list users by country.

 

Something like:

 

select countries from db

 

while{

 

echo"<h3>$row[country]</h3><br />";

 

          select * users where $row[country]

while{        echo"$row[company]<br />$row[address]<br />......... etc            }

 

 

{

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/147976-solved-list-users-based-on-country/
Share on other sites

<?php 

$sql = "SELECT * FROM table GROUP BY country, order by country";
$res = mysql_query($sql);
$strCurrentCountry ="";

while ($row = mysql_fetch_array($res)){

if($row['country'] != $strCurrentCountry) 
{ 
  $strCurrentCountry = $row['country'];
  echo"<h3>$row[country]</h3><br />";
}
  echo " $row[company]<br />$row[address]<br />
}

?>

 

something like this...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.