5 Replies - 371 Views - Last Post: 20 January 2012 - 04:26 PM Rate Topic: -----

Topic Sponsor:

#1 Malasuerte94  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-January 12

How i can reverse this ? (PHP)

Posted 20 January 2012 - 01:22 PM

   <?php
	
    	foreach ((array) comments($page_id) as $comment) {
			
    ?>
        <div class="comment shadow effect">
            <p class="left tip">
                <img class="avatar" src="<?php echo get_gravatar($comment['email'],40);?>" />
            </p>
            
            
            <p class="body right">
            <?php echo nl2br($comment['comment']);?>
            </p>
            
            
            
            <div class="detali_com">
            <div class="blue" style="width:50%; text-align:left; float: left; "><?php echo $comment['username'];?> Said</div>
            <div class="red"  style="width:50%; text-align:right; float: left;"><a href="#" onclick="$(this).delete_comment(<?php echo $comment['id'];?>); return false;"><span class="blue"><?php echo timeBetween($comment['time'],time());?></span> · Remove Comment</a></div>
            </div>
            </p>
            
        </div>
    <?php
    }
    ?>



ok and i wana reverse this comments'''
right now look like this
-------------



Jony say hello ! 4 hour ago
mant say ok ! 3 hour ago
cata say kkk ! 2 hour ago



and i want to have
cata say kkk ! 2 hour ago
mant say ok ! 3 hour ago
Jony say hello ! 4 hour ago


i search for this 2 hours :|.. how i can do this ?

Is This A Good Question/Topic? 0
  • +

Replies To: How i can reverse this ? (PHP)

#2 modi123_1  Icon User is online

  • Suiter #2
  • member icon


Reputation: 3550
  • View blog
  • Posts: 14,980
  • Joined: 12-June 08

Re: How i can reverse this ? (PHP)

Posted 20 January 2012 - 01:24 PM

Moving to the actual php sub forum.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2146
  • View blog
  • Posts: 5,429
  • Joined: 08-June 10

Re: How i can reverse this ? (PHP)

Posted 20 January 2012 - 01:49 PM

probably by using array_reverse() on the comments() function, though I don’t know the exact footprint of it so there may be issues.

This post has been edited by Dormilich: 20 January 2012 - 01:49 PM

Was This Post Helpful? 1
  • +
  • -

#4 Slice  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 122
  • View blog
  • Posts: 431
  • Joined: 24-November 08

Re: How i can reverse this ? (PHP)

Posted 20 January 2012 - 01:51 PM

I'm guessing the comments() function has your query to retrieve comments? You could simply add ORDER BY comment DESC to your query. (more info)

If that doesn't work, post the contents of your comment() function.
Was This Post Helpful? 1
  • +
  • -

#5 KuroTsuto  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 42
  • View blog
  • Posts: 182
  • Joined: 13-February 09

Re: How i can reverse this ? (PHP)

Posted 20 January 2012 - 02:16 PM

Both of the above answers would work. The PHP implementation of Dormilich's solution would be something akin to
<?php
	$comments = (array) comments($page_id);
	$comments = array_reverse( $comments, FALSE );

 	foreach ($comments as $comment) {

 ?>
     <div class="comment shadow effect">
         <p class="left tip">
             <img class="avatar" src="<?php echo get_gravatar($comment['email'],40);?>" />
         </p>
         
         
         <p class="body right">
         <?php echo nl2br($comment['comment']);?>
         </p>
         
         
         
         <div class="detali_com">
         <div class="blue" style="width:50%; text-align:left; float: left; "><?php echo $comment['username'];?> Said</div>
         <div class="red"  style="width:50%; text-align:right; float: left;"><a href="#" onclick="$(this).delete_comment(<?php echo $comment['id'];?>); return false;"><span class="blue"><?php echo timeBetween($comment['time'],time());?></span> · Remove Comment</a></div>
         </div>
         </p>
         
     </div>
 <?php
 }
 ?>



or, alternately choosing to omit the array_reverse funciton,
<?php
	$comments = (array) comments($page_id);
 	for ($i = count($comments) - 1; $i > 0; $i--) {

 ?>
     <div class="comment shadow effect">
         <p class="left tip">
             <img class="avatar" src="<?php echo get_gravatar($comments[$i]['email'],40);?>" />
         </p>
         
         
         <p class="body right">
         <?php echo nl2br($comments[$i]['comment']);?>
         </p>
         
         
         
         <div class="detali_com">
         <div class="blue" style="width:50%; text-align:left; float: left; "><?php echo $comment['username'];?> Said</div>
         <div class="red"  style="width:50%; text-align:right; float: left;"><a href="#" onclick="$(this).delete_comment(<?php echo $comments[$id]['id'];?>); return false;"><span class="blue"><?php echo timeBetween($comments[$i]['time'],time());?></span> · Remove Comment</a></div>
         </div>
         </p>
         
     </div>
 <?php
 }
 ?>


Was This Post Helpful? 3
  • +
  • -

#6 Malasuerte94  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-January 12

Re: How i can reverse this ? (PHP)

Posted 20 January 2012 - 04:26 PM

TNX ALL !!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1