I'm creating a website that shows 20 search results from the searched query, by taking the results from the database. If, in the address bar, the user has $n=(number) the number of results would be that number. So I thought of creating a button that resends the request but with $n=$n+10 , but that would refresh the page and I want a way to keep the user on the page and show 10 more results quickly and easily. Any ideas?
There are only two ways. Regular way that refreshes the page and ajax. If you are new to Ajax, I suggest you to use jQuery functions. It makes everything much easier to load that extra data and display them without refreshing the page.
http://api.jquery.com/category/ajax/
I suggest you to start with jQuery.post() function since you are new to this.
Related
I'm currently only using PHP to take user submissions, put them in a database, and echo them out on a page using SQL to select from a table, such as comments. I need a system that will automatically update comments without refreshing the page like on YouTube. The less the user has to manually update, the better.
I want it to work pretty much exactly how YouTube and Twitter function, where it'll say "x NEW COMMENT(s)" and clicking that updates everything.
My teacher recommended a JQuery function, but I don't have any background in that language so I don't know where to begin looking.
I'm at a complete impasse. I will update this if you guys need additional information to aid in my search.
You are looking for AJAX
You will need a HTML page with jQuery/AJAX that calls another PHP page. In that PHP page you do the DB request and then ideally return the data as JSON so that your frontend part can display it to the user.
As every one says, AJAX is the way. You can find a simple blog I did on it here.
I'm making a page which shows data, which is quite enormous.Tried pagination on it but didn't work the way I wanted. I'm looking for, something like "See more results", which on clicking will increase size of the page. Further, is it possible to do it with some limit on content to be shown on every click, like on every click it should show, say 10 or 15 rows ?
The best way to do this, in my opinion, is to cut the text and load just part of it with PHP. In this way the initial page won't be heavy. Then with a ‘Read more...’ button you can send an ajax request (with jQuery, maybe using the function load() function) you can get additional text, which will be appended in a div after the current text. Additionally, if you want to retrieve just some lines each time you press the button, you can check with jQuery how many div are already added (just adding a class to your new divs, you can check this just with $('#NameOfTheparent div.classOfTheNewDivs').length) and pass the variable to PHP, during the ajax request (so it won't be $('newDiv').load('something.php') but $('newDiv').load('something.php?var=numberOfDivAlreadyLoaded').
Well, this is the concept. :P
in my opinion, you need something like this:
http://andylangton.co.uk/articles/javascript/jquery-show-hide-multiple-elements/
First off I would like to say that I have done ample research on jquery pagination tutorials and scripts and the ones I have tried had worked, but just not the way I wanted them to.
What I am looking for is a jquery+php pagination that has 5 buttons. One for the first page, last page, next page, previous page, and manually enter a page to go to (which would also display the current page). I am new to pagination and have no idea how to integrate or alter current scripts, but I'm willing to learn as long as I can have the 5 buttons stated above and use php mysql queries. Thanks for the help!
UPDATE: I can do this with only php (would have to reload the page) but I do not know how to do this with jquery
UPDATE2: I figured out how to have the user manually input page number, but I still do not know how to do the other for buttons. For the next and previous buttons, I think I need to return the current page, but I have no idea how to do this :/
The trick is you use limit and offset parameters in your mysql query. Depending on what page number of the result you are serving, you can modify the ordered mysql query to fetch the result from that offset. It's pretty simple to work with that after you understand how to paginate in mysql queries.
In order to accomplish this you simply need to enable your application to make an ajax call to fetch the 'more info' results. That ajax call should take two parameters, an OFFSET and a LIMIT. Simply store these values locally in the application (via hidden elements, JS cookies, etc) to reference. Next time the 'more info' button is pressed you increment the OFFSET by the LIMIT and repeat.
NOTE: It's important that your query that is fetching the results is also using an ORDER BY. If you are relying on the server to order the results the same automatically you could potentially repeat results if the data is being updated often.
What I have is a search form that submits to the same page and it fetches the results using an AJAX request.
This uses the POST method and I am trying to figure out a way to try and do something along the lines of having a button to open this page in a new window to preserve the search parameters and results and to allow it to be bookmarkable somehow but I can't really think how to do this.
The other main reason for doing this is because the search results contain links to if a user clicks one and then clicks back all the form parameters are lost, I have worked around this by having the links open in a new window.
Any help, advice and opinions would be much appreciated.
If you do a GET method instead of POST, then the user will get to an URL with its form parameters in it.
It won't have to be ajax anymore
I am not sure the correct terminology for the process that I am trying to describe. I don't even know which platform is underlying the technique. If you understand my description, please give the link to the site(s) and or the keyword name of the process. I think it is done by AJAX, but I am not certain. I use php as the backend code, I just need to find a way to dynamically display the results. Please give suggestions. I forgot the name of the sites that use this, and my link history expired.
TIA
Description:
The page would have a search form and options. After the user submits, the search is initiated, and the results appear inside the dedicated result area. The page does not refresh, just the info inside the result area.
The display area will show 20 (or whatever) results (lines). There will be next, and previous buttons. If you hit next, the next set of results will display.
I am writing a code that generates 20 results for each display. There is no set number of results, so the results might have a start/first page, but do not have an end page.
Each time the user hits 'next', the program would generate/load new results. It would also store previous results, so that when a user hits 'prev', the previous results can instantly come up.
What techniques/program are theses?
Having recently handled pagination with Code Igniter (php framework), the following links might help you and anyone else out:
http://tympanus.net/jPaginate/
http://codeigniter.com/forums/viewthread/93045/
Usability is important and AJAX pagination introduces some important questions that need addressing regarding pagination, the following article will give some usability guidelines for displaying results in a table:
http://thedesignvanguard.com/crud-r-for-read
Code Igniter Prototype Framework Ajax Pagination:
http://codeigniter.com/wiki/AJAX_Pagination_with_CI_Pagination_Library/
Since we're using jQuery, we chose the following, Codeigniter jQuery framework for AJAX pagination
http://tohin.wordpress.com/2008/08/12/codeigniter-ajax-pagination/
http://tohin.wordpress.com/2008/10/07/codeigniter-ajax-pagination-exampleguideline/
It is not AJAX for sure.
Nobody uses AJAX for the pagination.
And there are about zillion pagination examples over internet
The only thing is never described in articles is how to persist search options for the other pages.
But it's simple enough: http_build_query() can help you
You need to have a GET/POST form submitted via AJAX which contains the fields in the search term and page number.
If you are going to set the page size to 20 results, page_num=4 will show results from 61-80 results.
Usually search results are GET instead of POST (Ex: See Google search results ) along with the page_number as another attribute and value.
#IVAN .. good to know that the library came helpful..
About that searching option; check the recent commit in github
http://github.com/neotohin/CodeIgniter-Ajax-pagination-Library there is an additional parameter added for searching.
I think the simple code in readme is enough for understanding the mechanism.
You could use datatables
https://datatables.net/
https://datatables.net/examples/data_sources/server_side.html
With this plugin using jquery also you could use server sided page request , you just have to handle the plugin post using Ajax.
post automatically sends row , page offset column, search criteria you just have to provide the json encode return
and the plugin automatically has library in featuring pagination, search sort number of rows per page and the table formatting.
Needed are jquery, and the plugin css and js for this to work
let me know if you understood my explanation.
thanks (=