Sort a table that is created using document.write() in javascript

I have written the following code that displays a table of 4 columns on ajax success. I wish to sort this table based on the 4 columns. I tried doing it using some readymade .js files available online. but, didn’t succeed. How can I achieve the requirement?

function Success(data)
{
var obj;
obj=JSON.parse(data);
document.write("<html><head><title>Service</title></head><body 
bgcolor=#FFFFFB>");
document.write("
"); document.write("

Details

"); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); document.write("
"); for(i=0; i"); document.write(""); document.write(""); document.write(""); document.write(""); document.write(""); } document.write("
"); document.write("Name"); document.write(""); document.write("Number1"); document.write(""); document.write("Number2"); document.write(""); document.write("Number3"); document.write("
"); document.write(obj[i]); document.write(""); document.write(obj[i+1]); document.write(""); document.write(obj[i+2]); document.write(""); document.write(obj[i+3]); document.write("
"); document.write("
"); document.write("</body></html>"); } </script>


Source: stackoverflow-javascript

select recent purchases from multiple mysql tables

So, I have 4 tables products1, products2, products3, products4 those all are tables containing products, so I need to select all those tables and sort them by recent purchases by latest date

I currently have the code only for one table, but I need to select all tables

    echo '<li>'.$row['product'].'  <font size="1" face="Tahoma" color="#CCC">at price</font> $'.$row['price'].'</li>';      }
    ?>

Any help would highly be appreciated!


Source: stackoverflow-php