DragonPrime - LoGD Resource Community

Coding Support => v0.9.7 Technical Help => Topic started by: Pffft on December 04, 2004, 07:37:53 PM



Title: Sorting Comments from Newest to Earliest
Post by: Pffft on December 04, 2004, 07:37:53 PM
Hi everyone...
I want to sort all of my village, shades, and wherever's comments from Newest (top) to Earliest (bottom) with the comment form box located at the top instead of the bottom.  Someone at LotGD.net told me that all I have to do is chance DESC in the viewcommentary function to ASC and then get my SQL to resort the comments from Newest to Earliest.  However, I don't know how to do the SQL query to do that.  

Can someone help me with this?   :'(


Title: Re:Sorting Comments from Newest to Earliest
Post by: Excalibur on December 05, 2004, 01:32:40 PM
Not too difficult to do  ;)
Open common.php and find the function viewcommentary
Few lines lower you'll find:
Code:
 $sql = "SELECT commentary.*,
                   accounts.name,
                   accounts.login
                   ,accounts.loggedin,
                   accounts.location,
                   accounts.laston
              FROM commentary
             INNER JOIN accounts
                ON accounts.acctid = commentary.author
             WHERE section = '$section'
               AND accounts.locked=0
             ORDER BY commentid DESC
             LIMIT ".($com*$limit).",$limit";
change the:
Code:
            ORDER BY commentid DESC
to:
Code:
            ORDER BY commentid ASC
To let the comment box appear at the top of commentary you need to move these lines (it may differ from yours as I've slightly modified them for my own use):
Code:
   if ($session[user][loggedin]) {
        if ($counttoday<($limit/2) || $session['user']['superuser']>=2){
            if ($message!="X"){
                if ($talkline!="says") $tll = strlen($talkline)+11; else $tll=0;
                $estrai="karnak";
                $restorepage=$session['user']['restorepage'];
                $paragone=strstr($restorepage,$estrai);
                //print("restorepage = $restorepage   paragone = $paragone<br>");
                if ($paragone === false){
                   output("<form action=\"$REQUEST_URI\" method='POST'>`@$message`n<input name='insertcommentary[$section]' size='40' maxlength='".(200-$tll)."'><input type='hidden' name='talkline' value='$talkline'><input type='hidden' name='section' value='$section'><input type='submit' class='button' value='Aggiungi'>`n".(round($limit/2,0)-$counttoday<3?"`)(Hai ancora ".(round($limit/2,0)-$counttoday)." commenti per oggi)":"")."`0`n</form>",true);
                   addnav("",$REQUEST_URI);
                } else {
                  if ($session['user']['dio'] == 0 or $session['user']['dio'] == 2){
                     output("<form action=\"$REQUEST_URI\" method='POST'>`@$message`n<input name='insertcommentary[$section]' size='40' maxlength='".(200-$tll)."'><input type='hidden' name='talkline' value='$talkline'><input type='hidden' name='section' value='$section'><input type='submit' class='button' value='Aggiungi'>`n".(round($limit/2,0)-$counttoday<3?"`)(Hai ancora ".(round($limit/2,0)-$counttoday)." commenti per oggi)":"")."`0`n</form>",true);
                     addnav("",$REQUEST_URI);
                  }else{
                      output("`@$message`n<input type='hidden' name='talkline' value='$talkline'><input type='hidden' name='section' value='$section'>`n`0`n</form>",true);
                      //addnav("",$REQUEST_URI);
                  }
                }

            }
        }else{
            output("`@$message`nSorry, hai esaurito i tuoi commenti in questa sezione per oggi.`0`n");
        }
    }
right before the SQL command seen before. Be sure to move ALL the code that is inside the parenthesis of if ($session[user][loggedin]) {[/i].

That's all  :)

Excalibur


Title: Re:Sorting Comments from Newest to Earliest
Post by: Pffft on December 05, 2004, 09:55:47 PM
Thank you.  8]  I will try this when my host is online again.  8]


Title: Re:Sorting Comments from Newest to Earliest
Post by: Excalibur on December 05, 2004, 10:31:35 PM
Thank you.  8]  I will try this when my host is online again.  8]
You're welcome  :)
I've already tested the mod on my local server and it works as you want.


Title: Re:Sorting Comments from Newest to Earliest
Post by: Pffft on December 08, 2004, 09:25:24 PM
I finally had the chance to make the changes, however it doesn't work completely.  What I did was change the DESC to ASC in the viewcommentary function, then moved that tidbit so it's above all the text.  All that worked.  The part that didn't is when the list goes over its max line per page output, the newest comment goes to the previous page.

For example, if my village commentary is set to 10 lines of text, the 11th newest one will be moved to the second page, so players will never see the newest comments after the 10th one.


Title: Re:Sorting Comments from Newest to Earliest
Post by: Excalibur on December 09, 2004, 03:14:21 AM
Doh  ::) I didn't wrote so many comments, so I haven't noticed that problem  :-[
I'll check again this evening when I'll be back home from work.


Title: Re:Sorting Comments from Newest to Earliest
Post by: Chaosmaker on December 09, 2004, 03:29:14 AM
Possible solution (without any guarantee - didn't test that ;)), do this instead of the DESC->ASC change:
Find: array_push($outputcomments[$sect],$out);
Replace with: array_unshift($outputcomments[$sect],$out);


Title: Re:Sorting Comments from Newest to Earliest
Post by: Pffft on December 11, 2004, 03:38:53 AM
What I did was instead of changing the DESC to ASC, I followed Chaosmaker's suggestion and it worked.  Then I followed Excalibur's suggestion on how to move the comment form box above all the text, and it also worked.  Then I had to move the refresh/next/previous links above as well.  That took me a few minutes to figure out, but I managed and everything works now.  CM & Exc - thanx for the help.  8]


Title: Re:Sorting Comments from Newest to Earliest
Post by: sixf00t4 on June 29, 2005, 09:58:41 AM
hmmm, is it possible to write a module to give the user an option to use alternate sorting?   I am thinking not...


Title: Re:Sorting Comments from Newest to Earliest
Post by: Selekta on June 29, 2005, 10:10:14 AM
Sure as hell wouldnt be easy. You'd have to alter a lot of documents. Have fun setting up the comment moderation window. :)


Title: Re:Sorting Comments from Newest to Earliest
Post by: Sichae on June 29, 2005, 10:41:03 AM
hmmm, is it possible to write a module to give the user an option to use alternate sorting?   I am thinking not...

Sixfoot, it would most definately have to be another variable passed down the viewcommentary string, and would not be a module, but a core modification. :)

© 2018 DragonPrime - LoGD Resource Community
Email Talisman: talisman -at- gmail.com
&oeXs)2U7=V BmܲV.U e=;p\}eG )Jj} C5EH7ˤH=j } mo|*Ŋw{drV_@IV>/- TFQJ׀̀Ve}l1,V O iNYx͘$e$;
Forums: Powered by SMF 1.1.21 | SMF © 2006-2007, Simple Machines