homepage Welcome to WebmasterWorld Guest from 54.166.105.24
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Order a msyql query with javascript
helenp




msg:4378374
 7:02 pm on Oct 23, 2011 (gmt 0)

Hi,
I have managed to change all my tables in my intranet to sort with javascript instead of using php.
However to do on my website (searcherbox) I cant use same script as I have all rows in one <td>.
So I been searching, posting, trying, and did not found much or better said dont understand much. Think I need to use object oriented javascript using array.
So far I have this, and no clue if will work if done correctly or I need another script:

<html>
<head>
<title>manipulating objects in an array.</title>
<script language=JavaScript type=text/javascript>
// Function sort()

// smaller to bigger
/* Only for numeric arrays */
//Sintaxis - nombre_array.sort(numeric_sort_min)
function numeric_sort_min(element1, element2){
return (element1 - element2)
}

// bigger to smaller
/* Only for numeric arrays */
//Sintaxis - nombre_array.sort(numeric_sort_max)
function numeric_sort_max(element1, element2){
return (element2 - element1)

}
//
//-->
</script>



</head>

<body>
<center><div id="numbers"></div></center><br>
<script language=JavaScript type=text/javascript>
<!--
var my_array1 = new Array(0,1,2,3,4,5,6,7,8,9)
function show_array1(){
var msg1=""

for (var ctr=0; ctr < my_array1.length; ctr++){
if((my_array1[ctr] === 0) && (ctr != my_array1.length - 1)){msg1+=my_array1[ctr]+ ",".fontcolor("red")}
else if(ctr == my_array1.length - 1){msg1+=my_array1[ctr]}
else{msg1+=my_array1[ctr]+ ","}

}
document.getElementById("numbers").innerHTML = "my_array1= new Array(".bold().fontsize(6) +
msg1.bold().fontsize(6) +
")".bold().fontsize(6)
}
show_array1()
</script>

<form name="form1" onsubmit="return false"><center>
<input type="button" value="Order bigger to smaller" onClick="my_array1.sort(numeric_sort_max);show_array1();">
<input type="button" value="Order smaller to bigger" onClick="my_array1.sort(numeric_sort_min);show_array1();"><br>

</center>
</form>
</body>
</html>


I changed the array to this:
var my_array1 = new Array("<?php echo $row["price"]; ?>")
However dont work,
if I put it befor the do { statement I get the price for the first row,
and if I put it after the do { statement I get the price for the last row, and of course dont order anything.
And also I want to be able to order alfabetic things not only numbers.

This is the query I want to reorder:

do {
echo "<tr>";
echo "<td class=searchertop><p><a href=".$row["link_ingles"].">".$row["id_propiedad"]."</a><br>".$row["text"]."<br>Pool: ".$row["pool"]."<br>Bedrooms: ".$row["bedrooms"]."<br>Bathrooms: ".$row["bathrooms"]."<br>Air-conditioning: ".$row["air"]."<br>Sleeps max.: ".$row["duermen"]." persons.<br>Internet: ".$row["internet"]."<br>Prices from: ".$row["price"]." /week.</p><a href=".$row["link_ingles"].">View details</a><p></p></td>";
echo "<td class=searchertop>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=".$row["link_ingles"]."><img class=borderfotos src=".$row["image"]." border=\"0\"></a></td>";
echo "</tr>";
echo "<td class='result'>&nbsp;</td>";
echo "<td class='result'>&nbsp;</td>";
} while ($row = mysql_fetch_array($result));

echo "</table> \n";


Somebody have a practical link that I can edit, as I cant write my own script as you can see :)

 

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