Sorting mySQL entries (posts) after output
Posted: Sun Sep 24, 2006 4:11 pm
I am currently writing a program. Now this program spits out posts in a crude CSS styled 1px border box for each post that is outputed.
The problem is, I can't really think of how I would sort each post by date.
Because of this part of the final code:
It is now an integer data type, therfore using the sort() function will not work (where I understand that this function can only be used with arrays).
Here is the final code for output:
The problem is, I can't really think of how I would sort each post by date.
Because of this part of the final code:
Code: Select all
$row = mysql_numrows($result);
$mysqldate = $row[0];
$cat = $row[1];
$daily = $row[2];
$i=0;Here is the final code for output:
Code: Select all
<?php
// dailies.php
include("db.php");
dbConnect("dailies");
echo "<h1>Dailies</h1>";
function showDailies() {
$query = "SELECT * FROM dailies";
$result = mysql_query($query);
$row = mysql_numrows($result);
$mysqldate = $row[0];
$cat = $row[1];
$daily = $row[2];
$i=0;
while ($i < $row) {
$mysqldate = mysql_result($result,$i,"date");
$date = date("F dS, Y", strtotime($mysqldate));
$cat = mysql_result($result,$i,"category");
$daily = mysql_result($result,$i,"daily");
echo "<div id='daily' style='border:1px #000 solid; margin-bottom:5px; padding:10px;'>";
echo "<h3>Posted on " . $date . " in " . $cat . "</h3>";
echo "<p>" . $daily . "</p>";
echo "</div>";
$i++;
}
}
?>
<html>
<body>
<?php showDailies(); ?>
</body>
</html>