Am I doing this right?

Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Loyalty Vaulient is offline
    MemberRank
    May 2012 Join Date
    MalaysiaLocation
    1,796Posts

    Am I doing this right?

    Recently I found this thread ..

    [UBERCMS] : Pages System in comment system of New - RaGEZONE - MMO development community

    So , I tried it on my cms , and I did it like this

    Code:
    <?php
    $getComments = dbquery("SELECT * FROM site_news_comments WHERE article='" . $articleid . "'"); // Find all comments 
        $count = mysql_num_rows(getComments); // Results 
        $pages = ceil($count / 5); // Calculate pages 
        $offset = $page - 1;          // 
        $offset = $offset * 5;      // Comments per page 
        $getComments = dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT 5 OFFSET " . $offset);  
    ?>
    <div class="habblet-container ">
      <div class="cbb clearfix notitle ">
        <div id="article-wrapper"><h2>Comments (<?php echo mysql_num_rows($getComments); ?>)</h2>
          <div class="article-meta"></div>
          <div class="article-body">
            <?php
    		if ($page == 1) 
                { 
                    echo "First&nbsp;&nbsp;"; 
                } 
                 
                else 
                { 
                    echo "<a href='articles?id=" . $articleid . "&page=" . 1 . "'>First</a>&nbsp;&nbsp;"; 
                } 
    
    for ($i = 1; $i <= $pages; $i++) 
            { 
                if (($page + 4) >= $i && ($page - 4) <= $i) 
                { 
                    if ($i != $page) 
                    { 
                        echo'<a name="pages" href="' . WWW . '/articles?id=' . $articleid . '&page='.$i.'">'.$i.'</a>&nbsp;&nbsp;'; 
                    } 
                    else  
                    {  
                        echo "<b>" . $i . "</b>&nbsp;&nbsp;";  
                    }  
                } 
            } 
                if ($page == $pages) 
                { 
                    echo "Last"; 
                } 
                 
                else 
                { 
                    echo "<a href='article.php?id=" . $articleid . "&page=" . $pages . "'>Last</a>"; 
                }  
            if(mysql_num_rows($getComments) == 0){
              echo 'Sorry, er zijn nog geen Reacties geplaatst!';
            }else{
              echo '<table width="528px">';
              while($Comments = mysql_fetch_array($getComments)){
              $getUserInfo = mysql_query("SELECT * FROM users WHERE id = '".$Comments['userid']."'");
              $userInfo = mysql_fetch_array($getUserInfo);
                      echo '
                      <tr>
                        <td width="90px" valign="top">
                          <div style="float:left"><img src="http://habbo.nl/habbo-imaging/avatarimage?figure='.$userInfo['look'].'&size=b&direction=2&head_direction=3&gesture=sml&size=s"></div>
                          ';
                          if($userInfo['rank'] > 8){
                            echo '<div style="position: absolute; z-index:1"><img
     
    src="http://127.0.0.1/swfs/c_images/album1584/AD1.gif"></div>';
                        }
                    echo '
                    </td>
                        <td width="427px" valign="top">
                          <strong>RE: %news_article_title%</strong><br /><br />'.$Comments['comment'].'
                        </td>
                      </tr>
              <tr>
                        <td width="90px" valign="top">
                        </td>
                <td width="427px" align="right">
                  <i>Posted by: <strong><a href="#">'.$userInfo['username'].'</a></strong>  On '.$Comments
     
    ['posted_on'].'</i><br /><br />
                </td>
              </tr>';
              }
              echo '</table>';
            }
            ?>

    But then , on my site , I get this

    Screenshot by Lightshot

    How am I to fix this problem? Please do help me


  2. #2
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,607Posts

    Re: Am I doing this right?

    dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT 5 OFFSET " . $offset);

    to
    dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT 5 OFFSET ".$offset."");

    Try that.

    Also why you use offset and not the LIMIT 0, 25 -> 25, 50 etc?

    So I would do it like:

    $page = 0;
    if(isset($_GET['page']))
    $page = abs((int) $_GET['page']);

    $min_comments = $page * 5;
    $max_comments = $min_comments + 5;

    dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT $min_comments, $max_comments");
    Last edited by The General; 12-12-13 at 09:57 AM.

  3. #3
    Loyalty Vaulient is offline
    MemberRank
    May 2012 Join Date
    MalaysiaLocation
    1,796Posts

    Re: Am I doing this right?

    Quote Originally Posted by HillBilly View Post
    dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT 5 OFFSET " . $offset);

    to
    dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT 5 OFFSET ".$offset."");

    Try that.

    Also why you use offset and not the LIMIT 0, 25 -> 25, 50 etc?

    So I would do it like:

    $page = 0;
    if(isset($_GET['page']))
    $page = abs((int) $_GET['page']);

    $min_comments = $page * 5;
    $max_comments = $min_comments + 5;

    dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT $min_comments, $max_comments");
    Thanks for your help man , I appreciate it. I tired your code

    Code:
    dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT 5 OFFSET ".$offset."");
    Still gave the same error , and I followed your advice and did this :

    Code:
    <?php
    $getComments = dbquery("SELECT * FROM site_news_comments WHERE article='" . $articleid . "'");
    $page = 0;
    if(isset($_GET['page']))
    $count = mysql_num_rows(getComments); 
    $page = abs((int) $_GET['page']);
    $min_comments = $page * 5;
    $max_comments = $min_comments + 5;
    $getComments = dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT $min_comments, $max_comments");
    ?>
    ans now I get this Screenshot by Lightshot


    There's supposed to be 3 comments there , it shows the count as 1 and there's no comment or user.

  4. #4
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,607Posts

    Re: Am I doing this right?

    I honestly dont know. I think you've done something wrong in your database. I could be wrong.

    what displays if you do var_dump($getComments); before the while() loop?

  5. #5
    Loyalty Vaulient is offline
    MemberRank
    May 2012 Join Date
    MalaysiaLocation
    1,796Posts

    Re: Am I doing this right?

    I get 500 internal server error

  6. #6
    Account Upgraded | Title Enabled! flx5 is offline
    MemberRank
    Nov 2009 Join Date
    GMT+1Location
    294Posts

    Re: Am I doing this right?

    Not an error within the database.
    Basically you start with $page = 0, which leads to the offset being negative ($offset = ($page-1)*5 = -5).
    Negative offsets are illegal.

  7. #7
    Loyalty Vaulient is offline
    MemberRank
    May 2012 Join Date
    MalaysiaLocation
    1,796Posts

    Re: Am I doing this right?

    Quote Originally Posted by flx5 View Post
    Not an error within the database.
    Basically you start with $page = 0, which leads to the offset being negative ($offset = ($page-1)*5 = -5).
    Negative offsets are illegal.
    Can yea help me fix it bro? I'm still learning this

  8. #8
    Account Upgraded | Title Enabled! flx5 is offline
    MemberRank
    Nov 2009 Join Date
    GMT+1Location
    294Posts

    Re: Am I doing this right?

    $page is never defined, thus I am assuming the GET parameter is page=#.

    => Add before
    PHP Code:
    $getComments dbquery("SELECT * FROM site_news_comments WHERE article='" $articleid "'"); // Find all comments 
    the following:
    PHP Code:
    $page 1;
    if(isset(
    $_GET['page']) && is_numeric($_GET['page']) && $_GET['page'$_GET['page'] > 0)
       
    $page filter($_GET['page']); 

  9. #9
    Loyalty Vaulient is offline
    MemberRank
    May 2012 Join Date
    MalaysiaLocation
    1,796Posts

    Re: Am I doing this right?

    It's giving me 500 internal server error

  10. #10
    Account Upgraded | Title Enabled! flx5 is offline
    MemberRank
    Nov 2009 Join Date
    GMT+1Location
    294Posts

    Re: Am I doing this right?

    Post the last few lines of your Apache error.log / IIS error log

  11. #11
    Gamma Spamma Liam is offline
    MemberRank
    Dec 2011 Join Date
    Down UnderLocation
    2,945Posts

    Re: Am I doing this right?

    Recoding a better one now for you all. I'll post it here once it's done :) It'll be much better than this one, give me about 10 minutes or so.

  12. #12
    Loyalty Vaulient is offline
    MemberRank
    May 2012 Join Date
    MalaysiaLocation
    1,796Posts

    Re: Am I doing this right?

    Quote Originally Posted by flx5 View Post
    Post the last few lines of your Apache error.log / IIS error log
    It's just one error , 500 internal server error

    Quote Originally Posted by Reverb View Post
    Recoding a better one now for you all. I'll post it here once it's done :) It'll be much better than this one, give me about 10 minutes or so.
    Alright mate , though it's been 6 hours :P

  13. #13
    Account Upgraded | Title Enabled! iRetro™ is offline
    MemberRank
    Feb 2010 Join Date
    United KingdomLocation
    558Posts

    Re: Am I doing this right?

    I seriously wonder why people would want to play a retro in which their owner can't even understand simple PHP.

    There was a little typo in this code so replace it with this.
    Code:
    <?php
    $getComments = dbquery("SELECT * FROM site_news_comments WHERE article='" . $articleid . "'");
    $page = 0;
    if(isset($_GET['page']))
    $count = mysql_num_rows($getComments); 
    $page = abs((int) $_GET['page']);
    $min_comments = $page * 5;
    $max_comments = $min_comments + 5;
    $getComments = dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT $min_comments, $max_comments");
    ?>
    Last edited by iRetro™; 13-12-13 at 01:00 AM.

  14. #14
    Loyalty Vaulient is offline
    MemberRank
    May 2012 Join Date
    MalaysiaLocation
    1,796Posts

    Re: Am I doing this right?

    Quote Originally Posted by iRetro™ View Post
    I seriously wonder why people would want to play a retro in which their owner can't even understand simple PHP.

    There was a little typo in this code so replace it with this.
    Code:
    <?php
    $getComments = dbquery("SELECT * FROM site_news_comments WHERE article='" . $articleid . "'");
    $page = 0;
    if(isset($_GET['page']))
    $count = mysql_num_rows($getComments); 
    $page = abs((int) $_GET['page']);
    $min_comments = $page * 5;
    $max_comments = $min_comments + 5;
    $getComments = dbquery("SELECT * FROM site_news_comments WHERE article = '" . $articleid . "' ORDER BY id ASC LIMIT $min_comments, $max_comments");
    ?>
    Tried it out , and it still gives me the same problem , not showing the comments and says that there's only one comment Screenshot by Lightshot

  15. #15
    Account Upgraded | Title Enabled! iRetro™ is offline
    MemberRank
    Feb 2010 Join Date
    United KingdomLocation
    558Posts

    Re: Am I doing this right?

    I'll add this to my site, with some edits and then I'll release. UberCMS only.



Page 1 of 2 12 LastLast

Advertisement