0

Ok here is the deal i am building a messaging system by php,ajax,jquery and mysql i add the new message and i add in 2 rows now what i want to do is to send an ajax request to server and recieve an updated version of the table but sorted So how can i do so

//here i add and call the message the message

function addMsg()
    {
      //alert(post);
        $.get("db.php",$('form').serialize(),
           function(data){
            getMsg(data);},"html");
}

function getMsg(data) { alert(data);
$("#t1").append(data); } //php

".""."".$row["col"]."".$row["col"]."".$row["col"].""; } ?>

//Now for sorting //javascript

function sort()
    {
        $.ajax({
          url: "sort.php",
          dataType: "text",
          success: function(data){
          $("t1").text(data);
              }

        });

    }

//php

$result = mysql_query("SELECT * FROM table ORDER BY col desc");

            while($row = mysql_fetch_array($result))
           {     
           echo "<tbody><tr><td>"."&#8226;"."</td><td>".$row["col"]."</td><td>".$row["col"]."</td><td></td><td></td><tr><td></td><td colspan='4'>".$row["col"]."</td></tr></tbody>"; 
           }

?>

2
  • It might make your question easier to read for everyone if you used a period once in a while. =] Commented Apr 13, 2009 at 14:41
  • Also, a few lines of your source code are formatted incorrectly. You need to put 4 spaces in front of "function getMsg(data)..." and "$result = mysql_query(..." Commented Apr 13, 2009 at 14:46

1 Answer 1

2

Use ORDER BY when you do the SELECT. Check this: http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.