homepage Welcome to WebmasterWorld Guest from 23.22.173.58
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Order mysql result
helenp




msg:4617630
 9:07 am on Oct 18, 2013 (gmt 0)

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.

 

Fotiman




msg:4617699
 4:06 pm on Oct 18, 2013 (gmt 0)

More info is needed. Specifically, the actual HTML output.

In JavaScript, if you've got an array you can sort it using:

yourArrayInstance.sort();

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

helenp




msg:4617735
 6:45 pm on Oct 18, 2013 (gmt 0)

More info is needed. Specifically, the actual HTML output.

In JavaScript, if you've got an array you can sort it using:

yourArrayInstance.sort();

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


Thanks, will have a look.

This is the html output and the query I want to be able to order:

More info is needed. Specifically, the actual HTML output.

In JavaScript, if you've got an array you can sort it using:

yourArrayInstance.sort();

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

helenp




msg:4617883
 5:12 pm on Oct 19, 2013 (gmt 0)

Uups,
See I pasted previous reply instead of the html and the query,
Here is my html and the query:

$result = mysql_query ("SELECT FORMAT(price_eng, 0) as price, propertytitle, text_eng, bedrooms, image, zona, id FROM ventas_buscador WHERE zona LIKE '%GM%'order by price_eng", $dbh);
if ($row = mysql_fetch_array($result)){
do {
echo "<table class='tabla' border='0'> \n";
echo "<tr>";
echo "<td class='searchertop'><p><a href=\"properties_for_sale_marbella.htm?id=".$row["id"]."\">".$row["propertytitle"]."<br>Property reference: ".$row["id"]."</a><br><p>".$row["text_eng"]."<br><br>Bedrooms: ".$row["bedrooms"]."<br>Price : ".$row["price"]."<br><br><a href=\"properties_for_sale_marbella.htm?id=".$row["id"]."\">View details</a></p><p></p></td>";
echo "<td class='searchertop2'><a href=\"properties_for_sale_marbella.htm?id=".$row["id"]."\"><img class='borderfotos' src=".$row["image"]." border=\"0\"></a></td>";
echo "</tr>";
} while ($row = mysql_fetch_array($result));

echo "</table> \n";

helenp




msg:4617928
 9:11 am on Oct 20, 2013 (gmt 0)

In JavaScript, if you've got an array you can sort it using:

yourArrayInstance.sort();

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?

Frank_Rizzo




msg:4617929
 9:43 am on Oct 20, 2013 (gmt 0)

A quick way would be to use a table that has sortable columns.

You can use jquery and plugins such as tablesorter.

helenp




msg:4617932
 10:22 am on Oct 20, 2013 (gmt 0)

A quick way would be to use a table that has sortable columns.

You can use jquery and plugins such as tablesorter.


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,

Fotiman




msg:4618017
 1:06 am on Oct 21, 2013 (gmt 0)

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.

helenp




msg:4618059
 6:44 am on Oct 21, 2013 (gmt 0)

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:

header 1, header 2, header 3, header 4
row1 row 1 row 1 row 1
row2 row 2 row 2 row 2

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

helenp




msg:4618064
 7:11 am on Oct 21, 2013 (gmt 0)

For easier view, I have deleted all php code and classes etc, and left the vars to sort by between " " calling them column 1, column 2 etc, as this information I get from mysql:

<table>
<tr>
<td><p><a href=\"properties_for_sale_marbella.htm>"Column 1"<br>Property reference: "Column 2"</p></a><p>"Column 3"<br>Bedrooms: "Column 4"<br>Price : "Column 5"<br><a href=\"properties_for_sale_marbella.htm>View details</a></p></td>";
<td><a href=\"properties_for_sale_marbella.htm><img class='borderfotos' src="Column 6" border=\"0\"></a></td>";
</tr>
</table>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved