Jump to content

[SOLVED] ordering results from db


squiblo

Recommended Posts

this code works well but does not order how i want, i would like the unread to be displayed first and by date order, then the unread displayed by date order, how can i do this?

 

<?php
$query = mysql_query("SELECT * FROM mail WHERE pageid='$pageid'");
$checkbox = 1;
while ($row = mysql_fetch_assoc($query)){
$subject = $row['subject'];
$message = $row['message'];
$from = $row['from'];
$when = $row['when'];
$read = $row['read'];
$date = date("d/m/Y", strtotime(" $when +0 year ")); //this is the only way i know of changing date format

if ($read == "n")
{
$readicon = "<img src='./Images/pageimages/unread_icon.png' alt='not read'>";
$startbold = "<b>";
$endbolt = "</b>";
}
else
$readicon = "<img src='./Images/pageimages/opened_icon.png' alt='read'>";

echo "<tr><td width='40%'><hr width='100%' height='1px' color='#E6E6E6'>  <input type='checkbox' name='checkbox$checkbox'>$startbold  $readicon -  $subject $endbold </td></tr>";
$checkbox++;
}
echo "<tr><td><hr width='100%' height='1px' color='#E6E6E6'>";
?>

Link to comment
https://forums.phpfreaks.com/topic/175444-solved-ordering-results-from-db/
Share on other sites

problem is described in the code...

 

<?php
$query = mysql_query("SELECT * FROM mail WHERE pageid='$pageid' ORDER BY read, when"); //from changing this line
$checkbox = 1;
while ($row = mysql_fetch_assoc($query)){ // i get an error on this line saying "supplied argument is not a valid MySQL result"
$subject = $row['subject'];
$message = $row['message'];
$from = $row['from'];
$when = $row['when'];
$read = $row['read'];
$date = date("d/m/Y", strtotime(" $when +0 year "));
//unread = n
if ($read == "n")
{
//unread
$readicon = "<img src='./Images/pageimages/unread_icon.png' alt='not read'>";
$startbold = "<b>";
$endbolt = "</b>";
}
else
//read
$readicon = "<img src='./Images/pageimages/opened_icon.png' alt='read'>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.