如果相同的id项目超过1,如何从mysql获取1项

i want to do. if same id content have more then 1 then just get 1 item from mysql. i don't know how to do this. below my MySQL query.

$myboxexi=mysql_query("select box.upload_type,box.id,box.box_type,box.page_name,box.title,box.connect,box.type,box.uid,box.description,box.image,box.url,box.status,box.date,box.time
from {$statement} where pages.uid='".$session_id."' or catsb.uid='".$session_id."' and box.status='".$approval."' order by box.id desc limit {$startpoint} , {$limit}");

problem is i am getting data from another table by (box.id) and some table have same items 4 time and i get 1 item 4 time. so i want to do get 1 item if any item more then 1

any one knows about this?

Use LIMIT 1 at the end of query

Also if you get 2 or more equal rows you can use DISTINCT or GROUP BY to get unique rows

DISTINCT syntax:

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 syntax:

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

in your case you can use distinct:

$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);

more about DISTINCT you may find here: http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html

more about GROUP BY you can find here: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html

Try to write formatted code. It is easy to debug by you and other programmers.