Jump to content

Recommended Posts

im joining a table onto the query to show how many likes a post has but it is displaying the post x amount of times depending on how many likes there are.

 

I think its something to do with the way im joining onto the pid of the post table:

 

$post_query = $link->query("SELECT p.*, u.*, l.*
            FROM ".TBL_PREFIX."posts as p
            JOIN ".TBL_PREFIX."users as u
            ON (u.u_username = p.p_poster)
            LEFT JOIN ".TBL_PREFIX."post_likes as l
            ON (l.l_pid = p.p_pid)
            WHERE p_tid = '$tid'
            ORDER BY p.p_time_posted ASC")or die(print_link_error());
    
    $likes = array();
    
    while($post_info = $post_query->fetch())
    {
        
        // SOF LIKE LIST
        if (count($post_info['l_pid']) >= 1)
        {
            $likes[] = $post_info['l_username'];
            $amount_likes = count($likes);
            $slice = array_slice($likes, 0, 4, true);
            $remain = array_slice($likes, 4, $amount_likes, true);
            $remain_num = count($remain);
            $like_list = '';
            
            if($amount_likes > 4)
            {
                for($i=0; $i<=3; $i++)
                {
                    $like_list .= profile_link($likes[$i]).', ';
                }
                $like_list .= 'and '.$remain_num.' other like this'; 
            }
            elseif($amount_likes <= 3)
            {
                for($i=0; $i<3; $i++)
                {
                    $like_list .= profile_link($likes[$i]).' ';
                }
                $like_list .= 'like this';
            }
        }

 

the likes are stored in their own database table seperate from the posts

any advice?

Link to comment
https://forums.phpfreaks.com/topic/227978-problem-with-query/
Share on other sites

Doddsey_65,

 

Can you execute a var_dump() then exit() after setting $post_info to see what is going on?

 

If it is displaying the post 10 times in a row because there are 10 likes then I would assume that it is the way the code displays the post and like on the page.

Link to comment
https://forums.phpfreaks.com/topic/227978-problem-with-query/#findComment-1175596
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.