PHP从表中获取所有结果,而不是一遍又一遍地获取相同的ID?

时间:2013-06-01 10:51:11

标签: php mysql pdo fetch

DB中的结果:

TID - message
1 - hi
1 - bye
2 - hi 
2 - hi
2 - bye

说明:

$new = $pdo->prepare("SELECT * FROM mybb_posts ORDER BY pid ASC LIMIT 1");

我不想两次获取相同的ID,只需要一次。

所以它会获取:

1 - hi2 - hi

我该怎么做?

2 个答案:

答案 0 :(得分:1)

thx为您的评论,编辑了我的帖子:

$new = $pdo->prepare("SELECT * FROM mybb_posts GROUP BY pid ORDER BY pid");

$new = $pdo->prepare("SELECT DISTINCT(pid) FROM mybb_posts ORDER BY pid");

答案 1 :(得分:1)

我猜这有效:

$new = $pdo->prepare("SELECT * FROM mybb_posts GROUP BY pid ORDER BY pid ASC");

在phpMyAdmin中测试时,它会返回:

PID - message
1   - hi
2   - hi