A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearSort using php and jquery - page 1
User InfoPosts
Sort using php and jquery#1
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(;

from: ajax.js

function sort(orderByType)
url: "sort.php",
type: "get",
data: "orderby="+orderByType,
success: function(data){


$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>"."&#8226;"."</td><td>".
$row["player_name"]."</td><td></td><td></td><tr><td></td><td colspan=(4(>".


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?

posted date: 2009-04-15 01:03:00

Re: Sort using php and jquery#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-15 01:03:01

Re: Sort using php and jquery#3
Hi, Sarah. Please, use the preview below the form when asking questions to make sure it's formatted correctly before submitting. To tell the form that what you're entering code, use four leading spaces.

posted date: 2009-04-15 01:06:00

Re: Sort using php and jquery#4
You should try: tablesorter its for sorting tables. And you don(t even need to use php with this solution just jquery. Hope its usefull.To reply to your comment on Daan(s anwser you could update tablesorter with ajax as described here.

posted date: 2009-04-15 01:11:00

Re: Sort using php and jquery#5
While this is true, sorting using the tablesorter plugin is almost unusable for larger tables. Just a heads up for Sarah!

posted date: 2009-04-15 01:14:00

Re: Sort using php and jquery#6
The answer of MrHus is correct but I think you are doing something wrong. Have you put a space between the field name and the sort direction or is it just like you wrote here?

posted date: 2009-04-15 01:19:00

Re: Sort using php and jquery#7
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:ORDER BY user_name".$orderBy);But should be:ORDER BY user_name ".$orderBy);

posted date: 2009-04-15 01:20:00

Re: Sort using php and jquery#8
Thank you so much for your concern MrHus,skorpan and Daan I can't use the tablesorter because i add 2 rows by ajax as for the space i added it and it worked never thoight that could be a problem now i want to update contents of HTML table by jquery how could i do that

posted date: 2009-04-15 03:19:00

Re: Sort using php and jquery#9
As Daan said you are missing the space and that is probably the cause, however I will add:You should probably check the result of the mysql_query() call because currently you don(t know whether that is failing or not, which could be the cause of your problem. For example:$result = mysql_query((SELECT ...();if (!$result) { die(mysql_error());}while($row = mysql_fetch_array($result)) {//etc.Also you shouldn(t really be building the SQL statement based on strings that have come from the browser, as these cannot be trusted, and someone could currently add malicious SQL into what you are executing. See SQL Injection.You could validate the string first which would be far safer, and is easy because you only have two possible values, e.g.if (isset($_GET[(orderby(]) && $_GET[(orderby(] == (DESC() { $orderBy = (DESC(;} else { $orderBy = (ASC(;}

posted date: 2009-04-15 04:17:00

Re: Sort using php and jquery#10
Hey tomhaigh Thank you so much for your concern you all seem to know your way around web coding now i need help i am still newbie and i want someone that i can discuss with and ask what can i do and what to do Also i want to update the content of the HTML table by jquery what should i do

posted date: 2009-04-15 05:49:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.