Jony Kale
Jony Kale

Reputation: 979

PHP fetch all results from table, not not fetch the same ID over and over?

Results in DB:

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

Statement:

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

I don't want to fetch the same ID twice, only once.

So it will fetch:

1 - hi and 2 - hi.

How do I do so?

Upvotes: 0

Views: 131

Answers (2)

d4Rk
d4Rk

Reputation: 6693

thx for your comment, edited my post:

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

or

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

Upvotes: 1

koesie10
koesie10

Reputation: 572

I guess this works:

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

When tested in phpMyAdmin it returns:

PID - message
1   - hi
2   - hi

Upvotes: 1

Related Questions