Log in

View Full Version : Resolved Help with accending and decending comment order.



xiofire
05-13-2009, 11:04 AM
I have never had so many problems with a simple little PHP comment script in my life.
But, maybe I'm just having a bad week.
Heres the problem:

http://content.screencast.com/users/xiofire/folders/Jing/media/03a6acb1-37ea-4349-8a22-1e65ae5b2aed/2009-05-13_0805.png

And the script:


<?php
}
$tbl_name2 = "CENSORED";

$sql2 = "SELECT * FROM $tbl_name2 WHERE CENSORED='$id'";
$result2 = mysql_query($sql2);

while($rows = mysql_fetch_array($result2)){
?>
<div style="margin-top: 10px; margin-bottom: 10px; border: 1px solid #666; -moz-border-radius: 5px; -webkit-border-radius: 5px; padding: 5px;">
<strong><a href="<?=$rows['a_web']?>"><?=$rows['a_name']?></a></strong>&nbsp;<small>said:</small>
<p>
<?=$rows['a_answer']?>
</p>
<small><span style="font-family: georgia; color: #666">Posted on <?=$rows['a_datetime']?></span></small>
</div>
<?php
}

$sql3 = "SELECT view FROM $tbl_name WHERE id='$id'";
$result3 = mysql_query($sql3);

$rows = mysql_fetch_array($result3);
$view = $rows['view'];

if(empty($view)){
$view = 1;
$sql4 = "INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'";
$result4 = mysql_query($sql4);
}

$addview = $view+1;
$sql5 = "update $tbl_name set view='$addview' WHERE id='$id'";
$result5 = mysql_query($sql5);

mysql_close();
?>

Any help? :D

forum_amnesiac
05-13-2009, 11:11 AM
Depends on how you are storing the variable "'a_datetime'".

If it is the unix date stamp then you can do a SORT on that field when you extract the records.

If it is not a numeric date stamp then you need to split the field and rebuild it into YYYYMMDDHHMM and then sort on that.

Schmoopy
05-13-2009, 11:25 AM
Should be a simple ORDER BY statement in the query, add something like:



"SELECT * FROM $tbl_name2 WHERE CENSORED='$id' ORDER BY `date`, `time` ASC";

xiofire
05-13-2009, 06:56 PM
You are very helpful, Schmoopy.
Thanks!

xiofire
05-13-2009, 07:00 PM
So I changed it to order by datetime and ID, and it works!
These forums are great!

Schmoopy
05-13-2009, 09:35 PM
Glad to hear it :)

Good luck with developing the rest of your site.