在查询结束时使用 LIMIT 1
此外,如果您获得 2 个或更多相等的行,您可以使用DISTINCT或GROUP BY来获得唯一的行
不同的语法:
SELECT DISTINCT t1.field1, t1.field2, t1.field3
FROM table1 AS t1, table2 as t2
WHERE t1.field1=t2.field1
AND t1.field1=value1
GROUP BY 语法:
SELECT t1.field1, t1.field2, t1.field3
FROM table1 AS t1, table2 as t2
WHERE t1.field1=t2.field1
AND t1.field1=value1
GROUP BY t2.field2
在您的情况下,您可以使用不同的:
$query = "SELECT DISTINCT box.upload_type, box.id, box.box_type, box.page_name, ";
$query .= "box.title, box.connect, box.type, box.uid, box.description, ";
$query .= "box.image, box.url, box.status, box.date, box.time ";
$query .= "FROM {$statement} ";
$query .= "WHERE pages.uid='".$session_id."' ";
$query .= "OR catsb.uid='".$session_id."' ";
$query .= "AND box.status='".$approval."' ";
$query .= "ORDER BY box.id DESC ";
$query .= "LIMIT {$startpoint} , {$limit}";
$myboxexi=mysql_query($query);
更多关于DISTINCT你可以在这里找到:http: //dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html
更多关于GROUP BY你可以在这里找到:http: //dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
尝试编写格式化代码。您和其他程序员很容易调试。