хорошо, у меня есть таблица продуктов. и стол для комментариев. пользовательская таблица и социальная таблица.
социальная
SID AUID BUID
1 1 2 // user 1 follow 2
2 1 3 // user 1 follow 3
3 2 1
мы видим, что идентификатор пользователя 1 следует за пользователем 2, а 3
Пользователь
UID NAME
1 me
2 imthenamefromuser2
3 imthenamefromuser3
продукт
PID UID NAME TIMECREATE
1 2 user2product 12-04-2011
2 3 user3product 12-03-2011
комментарий pcid = идентификатор родительского комментария
CID UID PID COMMENT PCID
1 1 2 comment on product2 NULL
2 2 2 another comment on p2 NULL
3 3 2 someoneelse on p2 NULL
4 1 2 who are you? 3
5 3 2 im user 3 dude 4
6 1 1 a new post on p2 NULL
хорошо, вопрос
как мы можем получить список товаров их подписчиков со следующими комментариями (максимум 20 комментариев)?
вот что у меня есть (без комментариев), давайте рассмотрим пример: $ uid: 1
function listFromFollower($uid){
#here
$data = $this->fetchAll("SELECT products.name AS product, users.name, products.pid, products.timecreate
FROM products
INNER JOIN users ON users.uid = products.uid
INNER JOIN social ON products.uid = social.buid
WHERE social.auid = :uid", array( 'uid' => $uid));
return $data;
}
получается что-то вроде
array
0 =>
array
'product' => string 'user2product' (length=9)
'name' => string 'imthenamefromuser2' (length=12)
'pid' => string '1' (length=1)
'timecreate' => string '2011-02-26 13:30:07' (length=19)
1 =>
array
'product' => string 'user3product' (length=8)
'name' => string 'imthenamefromuser3' (length=12)
'pid' => string '2' (length=1)
'timecreate' => string '2011-02-26 13:30:54' (length=19)
возможно, это должно быть что-то вроде
array
0 =>
array
'product' => string 'user2product' (length=9)
'name' => string 'imthenamefromuser2' (length=12)
'pid' => string '1' (length=1)
'timecreate' => string '2011-02-26 13:30:07' (length=19)
0 =>
array
'name' => string ''
'comment' => string ''
1 =>
array
'name' => string ''
'comment' => string ''
0 =>
array
'name' => string 'a threaded comment'
'comment' => string ''
untill20 =>
array
'name' => string ''
'comment' => string ''
1 =>
array
'product' => string 'user3product' (length=8)
'name' => string 'imthenamefromuser3' (length=12)
'pid' => string '2' (length=1)
'timecreate' => string '2011-02-26 13:30:54' (length=19)
Спасибо!