SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    more selective query - need a bit of advice

    Trying to show the latest threads the user started and the latest threads a user posted in.
    I'm having 2 problems with the latest a user posted in
    - Don't show threads the user has started under threads a user posted in
    - If a user has multiple post in one threads don't show thread multiple times


    PHP Code:
    //Mythreads Latest you started
    $Recordset1 mysql_query("SELECT * FROM `phpbb_topics` WHERE `topic_poster` = 2 ORDER BY `topic_time` DESC LIMIT 0 , 4") or die(mysql_error());
            
    $blue 0;
            while (
    $results mysql_fetch_array($Recordset1)) 
                        {
                                    
    $id[$blue] = $results[topic_id];
                                 
    $title[$blue] = $results[topic_title];
                                 
    $blue++;                
                                 if (
    $blue == 5) break;
                        }
    echo 
    "Threads you started:<br>";
    $blue 0;
    while (
    $blue 4) {
    echo 
    "<a href=\"http://www.top-download.net/forum/viewtopic.php?t=$id[$blue]\">$title[$blue]</a><br>";
    $blue++;
    }

    //Mythreads Latest you posted in
    $Recordset1 mysql_query("SELECT * FROM `phpbb_posts` WHERE `poster_id` = 2 ORDER BY `post_time` DESC LIMIT 0 , 4") or die(mysql_error());
            
    $blue 0;
            while (
    $results mysql_fetch_array($Recordset1)) 
                        {
                                    
    $id[$blue] = $results[topic_id];
                                 
    $title[$blue] = $results[topic_title];
                                 
    $blue++;                
                                 if (
    $blue == 5) break;
                        }
    echo 
    "<br>Topics you posted in:<br>";
    $blue 0;
    while (
    $blue 4) {
    echo 
    "<a href=\"http://www.top-download.net/forum/viewtopic.php?t=$id[$blue]\">topic$blue</a><br>";
    $blue++;


  2. #2
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok fixed the duplicate problem
    SELECT DISTINCT `topic_id` FROM `phpbb_posts` WHERE `poster_id` = 2 ORDER BY `post_time` DESC LIMIT 0 , 4
    Nice to know this

  3. #3
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Improved the coding and added name querying
    Still need to figure out how to stop threads started by you showing up as posted in.


    PHP Code:
    //Mythreads Latest you started
    $Recordset1 mysql_query("SELECT * FROM `phpbb_topics` WHERE `topic_poster` = 2 ORDER BY `topic_time` DESC LIMIT 0 , 4") or die(mysql_error());
            
    $blue 0;
            while (
    $resultst mysql_fetch_array($Recordset1)) 
                        {
                                    
    $idt[$blue] = $resultst[topic_id];
                                 
    $titlet[$blue] = $resultst[topic_title];
                                 
    $blue++;                
                                 if (
    $blue == 5) break;
                        }
    echo 
    "Threads you started:<br>";
    $blue 0;
    while (
    $blue 4) {
    echo 
    "<a href=\"http://www.top-download.net/forum/viewtopic.php?t=$idt[$blue]\">$titlet[$blue]</a><br>";
    $blue++;
    }

    //Mythreads Latest you posted in
    $Recordset2 mysql_query("SELECT DISTINCT `topic_id` FROM `phpbb_posts` WHERE `poster_id` =2
    AND `topic_id` != '
    $id' ORDER BY `post_time` DESC LIMIT 0 , 4") or die(mysql_error());
    $blue 0;
    while (
    $results mysql_fetch_array($Recordset2)) 
                        {

                                    
    $id[$blue] = $results[topic_id];
                                 
    $title[$blue] = $results[topic_title];
                                 
    $blue++;        
                                 if (
    $blue == 5) break;
                        }
    $Recordset2 mysql_query("SELECT * FROM `phpbb_topics`") or die(mysql_error());
    while (
    $results mysql_fetch_array($Recordset2)) 
                        {

                                 
    $names["$results[topic_id]"] = $results[topic_title];
                        } 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •