JavaScript and AJAX Forum

Hi, I have on my work list learn javascript and ajax for years, however ever have any time as this is very complex for me.

I need to be able to order a mysql result without doing the query again, so it should be javascript based. I have a javascript that order normal table data by the columns headers, but this only works when the data is displayed as a table. Like this: Header 1, header 2, header 3 and below the rows.

I have pages on wich the data from mysql are not displayed as a table and I need to be able to resort the result. The result is displayed like this: Header 1 Header 6 (image) Header 2 Header 3 Header 4 Header 5

So I has not been able to use the script I already have. Are there any scripts or easy tutorials for this purpose only on the net that I can edit to suite my needs? Any help is appreciated.

You can then replace the innerHTML of some element with the values in the array. But without seeing your markup, it's hard to provide useful help.

In any case, start here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

Let me see if I get somewhere with this, so if I am correct, the array is in the php var from the mysql query, so to try to do some tests with the examples on the link you gave me, first I need to convert the php var to a javascript var?

If I understand you correctly, you mean information from the database displayed as a table with columns and row that sort by the column header? This I already have in my intranet. But on website the information is not displayed as a table, so the script I use for tables in my intranet does not work for the pages on my web. Thanks,

1. The code you pasted is not HTML, it is the PHP that generates HTML. 2. The code you pasted contains a table even though you claim it doesn't, so I'm not sure what to believe. Either this isn't the code you're using, or you're mistaken about it not using tables.

1. The code you pasted is not HTML, it is the PHP that generates HTML. 2. The code you pasted contains a table even though you claim it doesn't, so I'm not sure what to believe. Either this isn't the code you're using, or you're mistaken about it not using tables.

I know its php with html, but its the same, its html using php, and yes it is a table but the result is not displayed as a normal table like this:

A sortable tablescript sorts by the headers, my script does not have any headers, even so, I added headers just to test, but it did only sort by the first header, suppose this is due to not being displayed as a table with table and rows. As you can see in the script there are only two <td> one with 5 vars in, and one with the image. So the output needs to be changed, wich I dont know if is possible, or to sort by something else than the columns headers (<td>) for exampel an array as said before. I need to be able to sort by vars that are in the same <td> so I cant add header to sort by