Ok, kinda like what the title says; I've been reccomended by you guys in previous threads of mine to use ajax in order to re-order search results.
Since the results could be on multiple pages, I will have to query the database and select only eg. 10 results at a time.
WIth the title of my search results, when the user clicks on it, the database will be re-queried and re-ordered based on the data in the particular column of the search results.
EG. We have:
Title; Date; Cost
IF the user, clicks on title, the database will be re-queried using 'ORDER BY', and select the first 10 (or whatever) results. If 'Title' has already been selected and the results are in alphabetical order, I will reverse their order.
Up until this bit, I don't think I'll have too many dramas.
What I WANT to do is re-display only the search results table rather than refresh the entire page.
1.) IS it possible to modify the URL of the current page when I use the javascript to re-display the search results?
2 (and most importantly).) I really don't understand ajax that well....yep i've read all the tutorials on here and google etc etc. so i was wondering if someone could point me in the right direction as to how I would go about doing what i want to do???
With regard to the javascript component, do I use some command like onClick( ), requery the database, then re-create the html for the table displaying the search results or what???
My apologies about the vagueness here.
ajax, pagination, and re-ordering of result list
Moderator: General Moderators
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Reason I put it here is because I couldn't find anywhere more relevant in these forums.
Also; seeing as I really didn't know where to start with this thing and I'd been told about it here in the PHP code area, I kind of assumed it had something to do with javascript accessing the server-side (ie. PHP) code and so figured someone would lead me in the right direction.
Well I'll try read more on this thing, but I wouldn't have posted blindly without spending 40min or so looking for info on it on the web.
If someone can even explain the basic concept that would be good....in particular, what alternatives are there to using XML seeing as you can use POST or GET to transfer the data to and from the client pc.
Also, if there's a more appropriate place to put this question, then feel free to move it (whoever has the privelages to).
Cheers.
Also; seeing as I really didn't know where to start with this thing and I'd been told about it here in the PHP code area, I kind of assumed it had something to do with javascript accessing the server-side (ie. PHP) code and so figured someone would lead me in the right direction.
Well I'll try read more on this thing, but I wouldn't have posted blindly without spending 40min or so looking for info on it on the web.
If someone can even explain the basic concept that would be good....in particular, what alternatives are there to using XML seeing as you can use POST or GET to transfer the data to and from the client pc.
Also, if there's a more appropriate place to put this question, then feel free to move it (whoever has the privelages to).
Cheers.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I think if you understand the parts involved in pagers it might make more sense to you. There is no difference design-wise between and GET pager and a AJAX pager. The only difference is where the parts go. The main parts are:
1. The pager which returns a subrange of a list of items based on values given to it.
2. The HTML rendering code that displays the items in HTML format.
3. The request code that asks for the appropriate subrange from the list
If you squint you can see the MVC pattern emerging from this (1=Model, 2=View, 3=Controller).
In a normal GET based pager, clicking on a paging link makes a request to a script. The first thing that happens is the Controller sorts out what the parameters are telling it to do. Then the script gets the appropriate subrange of items from the Model. And finally the View renders the data as HTML and sends the page back to the browser.
The AJAX version moves the Controller and View to the client as javascript code. So the javascript Controller sorts first out the request based on what was clicked. It then makes an AJAX call to a PHP script (the Model) that generates the subrange of items and outputs them as XML, JSON, delimited text, etc. Finally the javascript View code uses that data to build the HTML list and updates the Inner HTML of some part of the page with the new output. You could also keep the View in PHP and send formatted HTML if you like. Up to you.
1. The pager which returns a subrange of a list of items based on values given to it.
2. The HTML rendering code that displays the items in HTML format.
3. The request code that asks for the appropriate subrange from the list
If you squint you can see the MVC pattern emerging from this (1=Model, 2=View, 3=Controller).
In a normal GET based pager, clicking on a paging link makes a request to a script. The first thing that happens is the Controller sorts out what the parameters are telling it to do. Then the script gets the appropriate subrange of items from the Model. And finally the View renders the data as HTML and sends the page back to the browser.
The AJAX version moves the Controller and View to the client as javascript code. So the javascript Controller sorts first out the request based on what was clicked. It then makes an AJAX call to a PHP script (the Model) that generates the subrange of items and outputs them as XML, JSON, delimited text, etc. Finally the javascript View code uses that data to build the HTML list and updates the Inner HTML of some part of the page with the new output. You could also keep the View in PHP and send formatted HTML if you like. Up to you.
(#10850)