Results 1 to 2 of 2

Thread: querying 2 tables mixed results

  1. #1
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default querying 2 tables mixed results

    hi guys me again doing a simple chat system very basic at the moment but stuck with if user A posts then user B then A then B all works ok but when user A posts twice it still displays A,B,A,B not AA,B,A
    here is the script
    PHP Code:
    $result1 mysql_query("SELECT * FROM sms WHERE touser = '$user' AND fromuser = '$fromuser' ORDER BY time");
    $result2 mysql_query("SELECT * FROM sms WHERE touser = '$fromuser' AND fromuser = '$user' ORDER BY time");
    while(
    $row1 mysql_fetch_array($result1))
      {
    echo 
    $row1['message'];

    while(
    $row2 mysql_fetch_array($result2))
      {
    echo 
    $row2['message'];
    }


  2. #2
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    hey, I'm trying to rack up some 'thanks' on my profile so hook me up for this one!

    you need to do some work with arrays here:

    PHP Code:
    $result1 mysql_query("SELECT * FROM sms WHERE touser = '$user' AND fromuser = '$fromuser' ORDER BY time"); 
    $result2 mysql_query("SELECT * FROM sms WHERE touser = '$fromuser' AND fromuser = '$user' ORDER BY time"); 

    $messages1 mysql_fetch_array($result1);
    $messages2 mysql_fetch_array($result2);
     
    $messages array_merge($messages1$messages2);

    $sorted_messages array_orderby($messages'time'SORT_DESC'touser'SORT_ASC);


    echo 
    '<pre>';
    print_r($sorted_messages);
    echo 
    '</pre>'
    Let me know if you don't understand this, or need more help

  3. The Following User Says Thank You to crobinson42 For This Useful Post:

    TwitterRooms (04-03-2012)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •