searls03 Posted May 30, 2011 Share Posted May 30, 2011 how do I order two tables by date so that the most recent are first and the most unrecent last? like table 1 should be first then a table 2 then a table 1. does this make sense? Quote Link to comment https://forums.phpfreaks.com/topic/237929-order-dates/ Share on other sites More sharing options...
searls03 Posted May 30, 2011 Author Share Posted May 30, 2011 more specifically, with this code? <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="/login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; $userid = $row["userid"]; } ?> <?php include 'config.php'; include 'opendb.php'; // if no id is specified, list the available articles if(!isset($_GET['id'])) { $query = "SELECT * FROM messages WHERE recipient ='$name' order by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($from1, $recipient, $title1, $content, $id, $date, $read) = $row; if ($read == "1"){ $content1 .= "<table border='0' cellpadding='0' cellspacing='0' width='1200'> <tr><td valign='top' width='274'> $from1</td> <td valign='top' border='1' width='1025'><a href='message.php?id=$id'>$title1</a></td></tr></table><br /> "; }else{ $content1 .= "<table border='0' cellpadding='0' cellspacing='0' width='1200'> <tr bgcolor='#CCCC99'><td width='274'><strong>$from1</strong></td><td width='1025'> <a href='read.php?id=$id'>$title1</a></td></tr></table><br /> "; }} }else { // get the article info from database $query = "SELECT * FROM messages WHERE recipient='$name' ORDER by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; $to = $row['recipient']; $from = $row['from1']; $id = $row['id']; $read = $row['read']; } // if no id is specified, list the available articles if(!isset($_GET['id'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT * FROM comments WHERE recipient='$name' order by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($com_id, $userid, $id1, $id, $recipient, $comment, $sender, $title, $date, $read) = $row; if ($read == "1"){ $content1 .= "<table border='0' cellpadding='0' cellspacing='0' width='1200'> <tr><td valign='top' width='274'>$sender</td> <td valign='top' width='1025'> <a href='reply.php?com_id=$com_id'>$title</a></td></tr></table><br /> "; }else { $content1 .= "<table border='0' cellpadding='0' cellspacing='0' width='1200'> <tr bgcolor='#CCCC99'><td valign='top' width='274'><strong>$sender</strong></td> <td valign='top' width='1025'><a href='read1.php?com_id=$com_id'>$title</a> </form></td></tr></table><br /> "; } } } else { // get the article info from database $query = "SELECT * FROM comments WHERE recipient='$name' order by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $userid = $row['userid']; $id1 = $row['id1']; $id = $row['messageid']; $recipient = $row['recipient']; $comment = $row['comment']; $sender = $row['sender']; $title = $row['title']; $read = $row['read']; } include 'closedb.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/237929-order-dates/#findComment-1222634 Share on other sites More sharing options...
Maq Posted May 30, 2011 Share Posted May 30, 2011 I'm not sure what's happening in your code but ORDER BY date DESC is the correct way to extract the most recent records first. What's the problem and what's happening? Quote Link to comment https://forums.phpfreaks.com/topic/237929-order-dates/#findComment-1222641 Share on other sites More sharing options...
searls03 Posted May 30, 2011 Author Share Posted May 30, 2011 the problem is that I want display the order from both tables, so like it would be content from table1, table2, table1. it displays as table1, table1, table2. it puts them in the correct order, but not from both tables, so all table1's first in the right order, then all table2s in the right order, I want them to "intermix" so to speak..... Quote Link to comment https://forums.phpfreaks.com/topic/237929-order-dates/#findComment-1222644 Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 any other help? Quote Link to comment https://forums.phpfreaks.com/topic/237929-order-dates/#findComment-1223506 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.