  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                Code (SQL) 
-- Table structure for table `customer`
--
CREATE TABLE IF NOT EXISTS `customer` (
  `CustomerID` int(11) NOT NULL,
  `Name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `Address` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `Area` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `Province` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `Code` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `Country` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `Email` varchar(100) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `customer`
--
INSERT INTO `customer` (`CustomerID`, `Name`, `Address`, `Area`, `Province`, `Code`, `Country`, `Email`) VALUES
(1, 'Win Weerachai', '16 AB building', 'Wattana', 'Bangkok', '10110', 'TH', '[email protected]'),
(2, 'Jame Born', '26 SS building', 'Hoy Yod', 'Cheing Mai', '89400', 'TH', '[email protected]'),
(3, 'Chalee Angel', '28', 'Ad Raod', 'New York', '90210', 'US', '[email protected]'),
(4, 'Angle Smith', '1', 'wilton close', 'Middlesex', 'UB1OWW', 'UK', '[email protected]'),
(5, 'Sombat Soi', '123', 'Mueng', 'Chieng Rai', '15468', 'TH', '[email protected]');
(6, 'Ann Joy', '88', 'Oxford close', 'London', 'LD190DD', 'UK', '[email protected]'),
(7, 'Jill Grass', '88', 'Oxford close', 'NY', 'LD190DD', 'US', '[email protected]'),
(8, 'Anna Box', '66', 'West Wood', 'ABC', '1234', 'USSR', '[email protected]'),
(9, 'John  Smith', '18 CC building', 'Bang Yai', 'Bangkok', '10400', 'TH', '[email protected]'),
(10, 'Somsir Soi', '123', 'Mueng', 'Chieng Rai', '15468', 'TH', '[email protected]'),
(11, 'Rob Box', '66', 'West Wood', 'ABC', '1234', 'USSR', '[email protected]'),
--
-- Indexes for dumped tables
--
--
-- Indexes for table `customer`
--
ALTER TABLE `customer`
  ADD PRIMARY KEY (`CustomerID`);
  
 
คำสั่ง "php & msqli" การแสดงผล ทั้งหมด โดย จัดกลุ่ม Country, Province ให้อยู่ในรูปแบบนี้ 
 
- TH 
| 1 | Win Weerachai | ....| Bangkok |...| TH |.. 
| 9 | John  Smith | ....| Bangkok |...| TH |.. 
| 5 | Sombat Soi | ....| Bureerum |...| TH |.. 
| 2 | Jame Born | ....| Cheing Mai |...| TH |.. 
| 10 | Somsir Soi | ....| Chieng Rai |...| TH |.. 
 
 
- US 
| 7 | Jill Grass | ....| CL |... | US | .. 
| 4 | Chalee Angel | ....| New York |... | US | .. 
 
 
- USSR 
| 4 | Anna Box | ....| ABC |... | USSR | .. 
| 11 | Rob Box | ....| Berge |... | USSR | .. 
  
 
ลองทำโดย 
 
Code (PHP) 
   $serverName = "localhost";
   $userName = "root";
   $userPassword = "";
   $dbName = "customer";
	$conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);
	$conn->set_charset('utf8');
  	$sql="SELECT DISTINCT Country, Province FROM customer;";
	$query= mysqli_query($conn,$sql);
	while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
	{
	 //     $CustomerID=$result["CustomerID"];	   
		$Province=$result["Province"];
		$Country=$result["Country"];
	    echo "- ".$Country."<br>";
	    echo "+ ".$Province."<br>";
		echo "<br>";
 	}
 
 
 
 
ลองใช้คำสั่ง   
SELECT DISTINCT Country, Province FROM customer; 
มันออกมาแค่ตัวเดียว ปัญหาคือ แสดงผลไม่หมดด้วย 
 
- TH 
Bangkok 
 
- US 
CL 
 
- USSR 
ABC 
 
 
คิดไม่ออกว่า จะใช้คำสั่งอะไรต่อ ในการแสดงผลทั้ังหมด โดย จัดกลุ่ม "ประเทศ", "จังหวัด"  
ขอบคุณคะ
 
 
  Tag : PHP, MySQL               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2017-06-07 22:26:00 | 
                      By :
                          gju | 
                      View :
                          1074 | 
                      Reply :
                          2 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |