include_once("database.inc.php");
$connection = @mysql_connect($host, $user, $password) or die(mysql_error());
$db = @mysql_select_db($name,$connection) or die(mysql_error());
?>
$counting = 0;
$sql = mysql_query("SELECT * FROM `shouts`");
while($data = mysql_fetch_array($sql)){
$counting = $counting + 1;
}
// menampilkan 10 pesan terakhir
if($counting > 10){
$countlessten = $counting - 9;
$sql = mysql_query("SELECT * FROM `shouts` ORDER BY `shouts`.`id` ASC LIMIT $countlessten,10");
}else{
//else it doesn't matter, there's less than 10!
$sql = mysql_query("SELECT * FROM `shouts` ORDER BY `shouts`.`id` ASC LIMIT 10");
}
while($data = mysql_fetch_array($sql)){
$timestamp = $data['timestamp'];
$postedyear=substr($timestamp,0,4);
$postedmonth=substr($timestamp,5,2);
$postedday=substr($timestamp,8,2);
$postedtime=substr($timestamp,11,5);
$newpostedtime = "";
$nomilitary=substr($postedtime,0,2);
// format waktu am/pm
if($nomilitary >= 13){
$nomilitary = $nomilitary - 12 ;
$newpostedtime = $nomilitary ;
$newpostedtime .= ":" ;
$newpostedtime .= substr($postedtime,3,2) ;
$newpostedtime .= " pm";
}
if($newpostedtime != ""){
$postedtime = $newpostedtime;
}else{
$postedtime .= " am";
}
//tampilkan komentar yang diberikan
$shoutby = $data['shoutby'];
$shout = $data['shout'];
echo $postedmonth . "/" . $postedday . "/" . $postedyear . " at " . $postedtime ." -
" . $shoutby . " berkata: " . $shout . "
";
}
?>
Kunjungi website Ciebal