/    Sign up×
Community /Pin to ProfileBookmark

re-sort mysql output with javascript?

I have a list of businesses and owners that I am databasing. I have them listing on a page @ [url]www.richmediaproductions.com/list.php[/url] Is there a way I can have text above the first instance of each that is just a title saying business and member accordingly that will dynamically re-sort my list alphabetically depending on which heading is clicked? By default I have them sorting by company name. I thought it might be possible using javascript? but I’m not sure as I don’t know JS well at all…

Much thanks to anyone with input!!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@jabezJun 20.2005 — From Chapter 71 of the php manual.

//QUOTE

5. How can I pass a variable from Javascript to PHP?

Since Javascript is (usually) a client-side technology, and PHP is (usually) a server-side technology, and since HTTP is a "stateless" protocol, the two languages cannot directly share variables.

It is, however, possible to pass variables between the two. One way of accomplishing this is to generate Javascript code with PHP, and have the browser refresh itself, passing specific variables back to the PHP script. The example below shows precisely how to do this -- it allows PHP code to capture screen height and width, something that is normally only possible on the client side.

<?php

if (isset($_GET['width']) AND isset($_GET['height'])) {

// output the geometry variables

echo "Screen width is: ". $_GET['width'] ."<br />n";

echo "Screen height is: ". $_
GET['height'] ."<br />n";

} else {

// pass the geometry variables

// (preserve the original query string

// -- post variables will need to handled differently)

echo "<script language='javascript'>n";

echo " location.href="${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"

. "&width=" + screen.width + "&height=" + screen.height;n";

echo "</script>n";

exit();

}

?>

//UNQUOTE

You may be able to generate JavaScript with php. Then output your database

info into some php-generated JavaScript variables. Then build some JavaScript arrays, and populate them with the relevant data.

Then use JavaScript functions to resort the data in the arrays, as required.

Build the JavaScript arrays so that each column from the database row

result set, has one array, with the same array index.

That way, you can retrieve or sort an entire row, using the same row index mapped to each array. I hope this makes sense. I think the technical term

is 'parallel arrays'. I've not done this in practice, so remember, in theory,

theory and practice are the same, but in practice they are not!

HTH - Jabez
×

Success!

Help @thunder77 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...