I'm a C# developer for Windows and I know NOT THAT MUCH about web programming. I have developed a special search engine in Java. I want to create a php interface for it. For now, I managed to connect php and Java via a Web Service. I watched some tutorials for creating a search engine and I have some slight idea of what should I do but I don't know exactly what to do with some problems. Here's the scenario I want to implement:
An Index page with a search box, user types the search query in that page, some results shows, if the user scrolls down, more results shows (like Facebook). When user clicks on a result item's link, the browser then opens another page that shows the result (also in my app).
Now what I know is that the index page should be a HTML file with a Get method to a PHP file.
What I don't know is How to enable "more" results? For this, my php should send an array containing the URL of the previous results to my Java service, get the results, add them to the array and wait. The next time it should use this array.
Please let me know what code structure should I use for my app.
Thanks in advance.
Edit:
Requested code samples in java server:
public String processQuery(String query, List<String> previousURLs);
this will be called for the first time like this:
processQuery("test", null);
suppose it has returned 2 results with urls:
http://www.bing.com
http://stackoverflow.com
these will be stored in an array and the second time:
processQuery("test", previous);
this will return new results which will be added at the end of the page.
You need to use AJAX (Asynchronous JavaScript and XML) requests. Essentially as a user scrolls down the page this triggers a request to get more results. You'd probably do something like cache the last result id to know from where to get the next batch of results. You'll need to brush up your javascript and possibly jQuery in order to figure out how to implement all this - ie trigger the request, handle the response and append new elements to the DOM.
An example website that does this is Duck Duck Go. Their search results page dynamically appends new results as you scroll. Make sure you have Firefox + Firebug to inspect the page, the network requests that get made and to step through (debug) the running javascript.
I did it with the help of this tutorial:
http://www.9lessons.info/2009/07/load-data-while-scroll-with-jquery-php.html
Related
I am working on a site which has an animated background, the animation is powered by javascript and therefore when the user enters and submits a search it would be great if the animation were to continue smoothly whist the search was completed and results appended to the DOM.
I have managed to get to the point where the results of the search are returned to JS from an ajax request although inherently the url of the ajax request is different from the url currently displayed in browser.
So my goal is for the user to come onto the site at say, www.example.com/public/home/search
They type something into text input and press search, the url changes to something like
www.example.com/public/home/search?q=some+search+query or
www.example.com/public/home/search/somesearchquery or
www.example.com/public/home/search/#somesearchquery, etc.
but the page state remains the same, the results are appended to the DOM and no full reload occurs.
Returning to a url like the one above should load the page and send the query automatically, returning the page with the results already appended.
I don't know weather this is possible, with or without obeying the MVC pattern.
I am not using any mvc framework and would like to avoid it if I can but instead using a bare bones system similar to the one found at. https://www.youtube.com/watch?v=OsCTzGASImQ
Any ideas, suggestions, alternatives?
There are several answers here for "change URL without reload", for example: Modify the URL without reloading the page .
So, I think you just have to implement some solution from one of these answers and run some javascript that change the page.
You have to be careful, because the modified URL must to load the same version of the page the user is seeing after the changes caused by the javascript. Otherwise, if the user copy and paste the URL, he will not be happy.
One way to archive it is to create the javascript function that "updates" the page without reload it based on the text input (let's say, f). Then, if the user try to access directly the page
www.example.com/public/home/search?q=some+search+query
your server side code just return the page search with a call to this javascript function at the end, like that:
f("some search query")
so, this function will update the page and the final effect will be the same as the user just enter in the page and after tries to type some search query.
(Note that, this function f may be used in both cases: when users type the text to search and when users just paste the entirely URL).
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 have asked this question in a similar manner here before and got a mixed response.
Having done some more homework I feel the need to ask again as I am taking a far more logical view toward it.
I have a search box, I want to take the the query from the search submission, process it and return the result to an Iframe in another page.
Very much like a php email form, but with a twist.
Ideal Scenerio:
search box query > process the query( the query is sent to external server in a string and processed, then returned as a html page > page displayed in an Iframe on another page.
I would like any suggestions or example code would be good.
Only some suggestions as I've not ready code to show you here:
this seems to me the ideal situation to use AJAX.
BUT I'd create and use a box (with div tag) rather than using an iframe.
You should bind your searchbox submission with a function that make the ajax call to a script that process the search parameters and provide you with results.
Once results are ready, your function callback will make them appear in your box (modifying the inner html contents of the box).
I think MAYBE you could get same result with an Iframe but, personally, I don't like using frames.
Hope to have helped you.
Here for you a little ajax tutorial showing just something like the thing you need
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 (=
I'm now developing comment system for my site on Ruby on Rails.
I try to make comments to be appeared when user click on SEE MORE button.
I see this is not like we do in pagination, so I need your little help guys!
When all comments have been displayed, the SEE MORE button should be removed from the page.
When the page loads, include a Javascript variable to indicate the "last item seen" or a time stamp (which I believe Twitter does as it orders the tweets in date order). You then have a Javascript function initiated by the setTimeout function which polls your server with this timestamp.
Your server then looks up to see if there has been any more posts since that point and if there has been, returns the number of results to the Javascript with an instruction to show a "See more" prompt - it also includes a new timestamp (if there are no new results, it just returns a timestamp).
Clicking on the "See more" prompt will then load in the new posts via Javascript, display them via the DOM and then reset the Javascript variable and repeat the process.
Of course, how you actually implement this will depend on how your data is structured, the server software you are actually using, what you actually want to do on the client side if there are new posts and then have often you want to "poll" the server for new responses (baring in mind more frequent polls will increase your server load).
Have you checked out this JQuery plugin. I believe it does pretty much exactly what you're looking for, and the example shows how to set it up using Rails. It's styled on the Facebook "Show more posts" pagination but this is basically the same as the "More" posts pagination as used by Twitter.