0
我的查詢是:
$sql = "SELECT * FROM $table WHERE ";
switch($type) {
case "global":
$sql .= "1 ";
break;
case "device":
$sql .= "udid = '$udid' ";
break;
case "name":
$sql .= "name = '$name' ";
break;
}
$sql .= "ORDER BY $sort ";
$sql .= "LIMIT $offset,$count ";
$result = mysql_query($sql,$conn);
的UDID是一個唯一的標識符。而循環:
while ($row = mysql_fetch_object($result)) {
echo '<tr>
<td>
'.$rank.'
</td>
<td>
'.$row->name.'
</td>
<td>
'.$row->score.'
</td>
<td>
'.$row->udid.'
</td>
</tr>';
$rank++;
}
這顯示了一個表如下:
rank name score udid
------------------------------------------------------
1 Joe 2.30101 49beeb956274dfb8406d66f7403dd4bf3d9c6da9
2 John 2.41940 119d62e398bf6f1cea89b235b5c8ecf95255442e
3 Frank 2.64561 another id
4 Mitt 3.00101 another id
5 Sean 3.10001 another id
這工作得很好,但如果我想給出一個對UDID的分數和排名,所以如果我想的UDID :119d62e398bf6f1cea89b235b5c8ecf95255442e我想獲得排名2,名字約翰和得分2.41940。
我該怎麼做?
喬
如果您運行相同的查詢,但將LIMIT $ offset,$ count改爲LIMIT,則會發生什麼情況($ offset + $ rank)。「,1'? – Travesty3 2012-02-29 20:04:07
或實際上'($ offset + $ rank - 1)' – Travesty3 2012-02-29 20:05:30