|
 |
|
เรียงค่า max ถ้าซ้ำกัน ก็ไม่เอา ช่วยหน่อยน่ะค่ะ T-T |
|
 |
|
|
 |
 |
|
MAX & GROUP BY
|
 |
 |
 |
 |
Date :
2012-03-25 08:28:53 |
By :
50121680 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้ค่ะเคยรองแล้วค่ะ
จากที่ใช้ MAX & GROUP BY
memberid / messageid
Array[0] = 47 / 177
Array[1] = 46 / 178
Array[2] = 46 / 176
Array[3]= 1 / 171
Array[4]= 1 / 189
Array[5]= 1 / 192
Array[6] = 1 / 194
Array[7] = 1 / 203
เคยใช้ max messageid , GROUP BY memberid
จะได้ค่านี้แทนค่ะ
Array[0] = 47 / 177
Array[2] = 46 / 176
Array[3]= 1 / 171
ทีผลลัพธ์ที่อยากได้คือ
memberid / messageid
Array[7] = 1 / 203
Array[1] = 46 / 178
Array[0] = 47 / 177
ด้านล่างคือ โค๊ด
Code (PHP)
$memberid_value2=$_SESSION["memberid"];
$numssort = 0;
$sqlsort="SELECT * FROM table_message where memberid=".$_SESSION["memberid"]." or friendid = ".$_SESSION["memberid"]." order by message_id ASC";
//echo "SQL2 = ".$sqls2."<br>";
$resultssort=$db->query($sqlsort);
$numssort=$resultssort->size();
if($numssort>0){
for($i=0;$i<$numssort;$i++){
$rowssort =$resultssort->next();
$message_sort=$rowssort['message_id'];
$friendid_sort=$rowssort['friendid'];
}
}
$array[$i] = $friendid_sort;
$arraym[$i] = $message_sort;
for($i=0;$i<$numssort;$i++){
for($j=0;$j<$i;$j++){
if ($array[$j]<$array[$j+1]){
$temp = $array[$j+1];
$array[$j+1] = $array[$j];
$array[$j] = $temp ;
$tempm = $arraym[$j+1];
$arraym[$j+1] = $arraym[$j];
$arraym[$j] = $tempm ;
}
}
}
for($i=0;$i<=$numssort;$i++){
echo "numx ". $i . " = ". $array[$i] . " / message = ". $arraym[$i] ."<br>";
}
|
 |
 |
 |
 |
Date :
2012-03-25 09:41:52 |
By :
จั๊กจั่น |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
SELECT `memberid`,MAX(`messageid`) as MAX FROM `test`GROUP BY `memberid` ORDER BY MAX DESC
|
 |
 |
 |
 |
Date :
2012-03-26 09:36:47 |
By :
50121680 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ยืนยันครับ
|
 |
 |
 |
 |
Date :
2012-03-26 09:38:57 |
By :
50121680 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|