How to create Search Box without using plug-ins? - php

I'm new to this and doing some research on how to create a Search Box from scratch (without using plug-ins like Google, etc).
The idea is to search within a particular website NOT all websites like Google does. Search results need to be displayed on that particular website.
Preferably using JS and PHP.
Please advise. Thanks.

its pretty simple.
from javascript/DOM you need: onkeypress or onkeyup.
plus ajax technology to send it while user is on your page ( without redirects. but I think its better to not use ajax in this subject )
from php you need an "handler" script which
will get your requests from your search field ( input type=text ) and search data in your DB using simple SELECT (you can use LIKE option).
and then you fetch all results form your request to your result page.

Related

How to create a search system like Unsplash?

When I create a search bar I always use the GET method. If a person searches for the word "code" the link will be: www.mywebsite.com/search?q=code
But at Unsplash, when you search the word code the link will be:
https://unsplash.com/search/photos/code
I copied this link, and I wrote all the words, even my first name (https://unsplash.com/search/photos/zayad) and I found a page with the images related to the searched words.
Do you have an idea on how, can I do the same thing in my website?
JavaScript. They intercept the form submission, update the address bar and redraw the page using JavaScript.
On the results page, they parse the URI in the address bar, make an AJAX request based on the search term they extract, and then update the page with the returned results.
Unsplash uses angularjs, that allows you to pass text from your text box as parameters quite easily. Wappalyzer says that Unsplash uses angularjs. Check out angularjs

Auto-update Posts without refreshing

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.

taking form input / processing / returning information on another page

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

How to enable "more" search results?

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

Recommendation for a Pagination procedure AJAX PHP

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 (=

Categories