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>'.'•'.'</td><td>'.$row['col'].'</td><td>'.$row['col'].'</td><td></td><td></td><tr><td></td><td colspan='4'>'.$row['col'].'</td></tr></tbody>'; }
?>
Use ORDER BY when you do the SELECT. Check this: http://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html