I’m trying to re-order a HTML table when the user clicks on the table header. Here is all I can do, but still doesn’t work.
in the HTML:
// onClick on table header var par='ASC'; sort(par);
from: ajax.js
function sort(orderByType) { $.ajax({ url: 'sort.php', type: 'get', data: 'orderby='+orderByType, success: function(data){ alert(data); $('t1').text(data); } }); }
sort.php
$con = mysql_connect('localhost','root','root'); if (!$con) { die('Could not connect: ' . mysql_error()); } $orderBy = $_GET['orderby']; mysql_select_db('icrisis', $con); $result = mysql_query('SELECT * FROM messages,user where user_id = from_user ORDER BY user_name'.$orderBy); while($row = mysql_fetch_array($result)) { echo '<tbody><tr><td>'.'•'.'</td><td>'. $row['Time_Date'].'</td><td>'. $row['player_name'].'</td><td></td><td></td><tr><td></td><td colspan='4'>'. $row['msg_desc'].'</td></tr></tbody>'; } mysql_close($con);
It doesn’t see the $orderBy. And then I want to add the new order to my page – how could that be done?
Could the variable sent to function sort be dynamic, i.e. to be ASC or DESC on click?
I’m not sure if that is the cause of your problem, but I believe you miss a space.
The last line of your query is now:
But should be: