2014-08-21, 07:38 PM
2014-08-21, 07:47 PM
Edit: Apparently I had misread your post. If you only need the UID, a simple left join will work.
Haven't tested it, but something like that should do the trick.
$query = $db->query("
SELECT *
FROM ".TABLE_PREFIX."table t
LEFT JOIN " . TABLE_PREFIX . "posts p ON p.uid = t.post_id
WHERE post_id=". (int) $PostID);
while($querydata = $db->fetch_array($query)) {
echo $querydata['uid']; // echo UID
}
Haven't tested it, but something like that should do the trick.
2014-08-21, 09:32 PM
there is a uid field in the posts table.
just a simple select on the posts table where pid=<post_id> andr equest the <uid> field.
just a simple select on the posts table where pid=<post_id> andr equest the <uid> field.
2014-08-21, 10:49 PM
I have post PIDs and I try to:
Fetch post username
Count POSTs with the same UID
Fetch post username
Count POSTs with the same UID
SELECT u.uid, u.username, post_id, COUNT(post_id) AS count
FROM ".TABLE_PREFIX."post_pids
LEFT JOIN ".TABLE_PREFIX."users u ON (post_id=u.uid)
group by post_id ORDER BY count DESC
2014-08-22, 05:09 AM
(2014-08-21, 10:49 PM)marcus123 Wrote: [ -> ]I have post PIDs and I try to:Meant, you have only $some_post_id, and want to know who made this post and how many other posts he made ?
Fetch post username
Count POSTs with the same UID
SELECT username, count(pid) as countofposts FROM ".TABLE_PREFIX."posts
WHERE username = (SELECT username FROM ".TABLE_PREFIX."posts WHERE pid=".$some_post_id.")
This will return username, countofposts
But if you meant that you have many PID's in custom table (table name post_pids with column post_id) and want to select each post_id directly from there, then find user who made this post and count his total posts then you could do something like this
SELECT username, post_id, (SELECT count(pid) FROM ".TABLE_PREFIX."posts WHERE username=mp.username) as countofposts
FROM ".TABLE_PREFIX."post_pids cp
LEFT JOIN ".TABLE_PREFIX."posts as mp ON (mp.pid=cp.post_id)
and you will get array with username, post_id, countofposts for each post_id from post_ids table
(if you need uid too, you can simply add it after first select like SELECT uid, username, post_id ect ect)
2014-08-22, 10:26 AM
Thanks very much +1. I made a few changes to your query and works awesome