View Full Version : Search Functionality
I am looking to start coding the search portion of my website. My knowledge in PHP is minimal, but I can get by in alot of cases. I know most HTML.
I really like the search bar that facebook.com uses and sonicelectronix.com uses. Specifically how when you begin typing, it first appears to search page titles, then if nothing found, search page content. Or something like that.
Can someone point me in the right direction of what I am looking for? I realize there will not be a script for exactly what I want, which is perfectly OK. I'm willing to at least make a hard attempt at getting this to work.
My live website is straycreations.com. I have added the textbox at the bottom of the page for now and am going to be eventually moving it over the search bar image I have in the navigation area.
My questions are as follows:
1) Most efficient, cleanest, good looking search method/script?
2) Can I just use a div to position my textbox to hover over the search image?
3) Recommendations? Pointers? Tips? Anything! :D
james438
12-21-2010, 10:17 AM
Sites that have search scripts that will search their own site as opposed to a google addon almost always search their database where they store much, if not all, of their site content.
I have a search script on my own site, which I have worked off and on for a few years before I got it to where I wanted it. When I began work on it I started with a script from this page: http://www.designplace.org/scripts.php?page=1&c_id=25.
It is very simple and is not perfect, but it should help you get started.
Before you do anything, though, you need to get a database set up for your site, preferably MySQL. It can be difficult to create, but unlike HTML, PHP, or javascript, there are very few things you need to learn. When I say that it is difficult, I mean it is difficult to understand conceptually. MySQL is about storing and retrieving data. It is like a glorified spreadsheet. The geratest benefit of MySQL is that it can sort and process your data in many many ways, which becomes increasingly important the more data you work with.
I'm sure there are several people here on this site who will be happy to help you along the way to creating a search script. I have to say that creating a search script is rather complicated and involves many different aspects of php and MySQL, but, again, there are people here to help.
Shaggy21
12-21-2010, 10:42 AM
Sites that have search scripts that will search their own site as opposed to a google addon almost always search their database where they store much, if not all, of their site content.
I have a search script on my own site, which I have worked off and on for a few years before I got it to where I wanted it. When I began work on it I started with a, remove duplicates (http://www.ashisoft.com) script from this page: http://www.designplace.org/scripts.php?page=1&c_id=25.
It is very simple and is not perfect, but it should help you get started.
Before you do anything, though, you need to get a database set up for your site, preferably MySQL. It can be difficult to create, but unlike HTML, PHP, or javascript, there are very few things you need to learn. When I say that it is difficult, I mean it is difficult to understand conceptually. MySQL is about storing and retrieving data. It is like a glorified spreadsheet. The geratest benefit of MySQL is that it can sort and process your data in many many ways, which becomes increasingly important the more data you work with.
I'm sure there are several people here on this site who will be happy to help you along the way to creating a search script. I have to say that creating a search script is rather complicated and involves many different aspects of php and MySQL, but, again, there are people here to help.
I Got Some Knowledge!
You seem to have understand what I was asking for on the dot. Thank you.
I know a tiny bit about mysql, but only the knowledge gained from a few years of trying every cms portal with a database installer built in that google could find. I really want to start applying what I know and start making a database for my website. I have had dozens of "versions" of my html websites over the past 5 years or so, every one of them in my oppinion a little bit cleaner and better. Now I find myself wondering the what the best and most efficient method is to organize my pages and setup the display of my pages so in the long run as I begin forming a database and working on a search script it will be quick and fluid and browser universal. I use iframes right now because it's simple to me, but I KNOW that can't be the best way to go. I just discovered <?php includes and am going to start using header/footer/body includes on my site tomorrow when I get around to spending some time on it. I also just began using <div's used with hyperlinks over my main navigation background image for the navigation, which I had never attempted before. What's efficient? I know iframes can't be..
I saved that php script you linked to my desktop and I will look at it and try to understand all of it tomorrow, i'm tired right now. :P
update: (by the way creating my database now.)
update: Dammit i'm going to sleep for the night. For not knowing mysql or much php, I get around semi-decent. I got stuck on line 36? im puzzled.
fastsol1
12-21-2010, 02:03 PM
Here is a great tutorial to get you started. It is based on the google search bar.
http://www.youtube.com/user/phpacademy#p/u/2/kQ2k2eunXTw
james438
12-22-2010, 03:25 AM
The files that you are used to working with are known as flat files. Includes are a great way to load things like headers and footers on many pages. Now when you update your include file the headers and footers for all of the pages that have them will be updated as well. Not sure if that made sense, but I believe you already have some idea of how includes work already.
Creating a database takes a little patience. It can take many hours for the database to get set up on the server after you have asked your web host to set it up. Once you have it set up you will probably have a phpmyadmin page where you can create some tables with a few columns.
Once you are comfortable creating tables and adding columns and storing some data into one of your tables we'll try and create a little script where you can more easily upload content to your database.
Databases are good for storing text documents, numbers, images (although many people store their images in folders on their hosting site, which is what I do).
I am using the phpmyadmin that is provided by my host (godaddy) which is hosted on some domain. Should i ditch that and just install my own phpmyadmin and start the database over so it is actually hosted on my domain?
Also. I am still stuck on line 36 which is the code that returns the number of rows (results) i believe, and I think it's because i dont have any rows in my table. Any more hints on where I can find some very very basic info on how to begin forming my tables and start putting content in?
Lastly, I don't know what content I should be putting in and how to organize it. I know I eventually want to add some sort of username/password login/registration functionality but i'll get to that later. Right now i'm trying to stay focused on this search. Re-check out my live site please, when you enter a search query it returns with that line 36 error. Tadabases, tables, and content oh my! Overwhelming, but i'm learning so much.
Thank you for your continued support, you guys are all very helpfull and informative. Thanks in advanced for everything.
fastsol1
12-22-2010, 09:20 PM
The youtube channel I gave you the link to has a ton of tutorials on all the stuff you are asking about. This guy is very easy to follow and explains what he is doing and why.
james438
12-23-2010, 12:00 AM
Stay with the phpmyadmin that you have unless you have a reason to use another service.
As far as line 36 goes I believe that you are right about why it is not searching correctly; you don't have anything for the program to search yet. That script I pointed you to IS very elementary and has not been updated in some years, but I believe that it gives you some idea on what a search program like the one you are talking about looks like.
I should stop here and mention that there are addons that you can get for your site from google that will search your site using a google search. You can certainly go that route, but I am not a big fan. Here is a link to it though: http://www.google.com/sitesearch/
I decided to create my own, because I wanted greater control over what was searched, how it searched, and what was considered a match. For example, if I searched for "foggy" I did not want it to match "fog", just "foggy". Does that make sense?
I am not aware of any good tutorial sites on MySQL. I usually just visit the MySQL dev site (http://dev.mysql.com/doc/) and read up on what I want to know, although I will admit that they are not nearly as easy to understand as php.net (http://php.net) is.
There's not much to learn, though, with MySQL. To start, in phpmyadmin go to the left hand side of the page and hit the sql button. Here a dialog box will pop up where you can create some sql queries.
Here is a quick table:
CREATE TABLE tablename
(ID INT NOT NULL AUTO_INCREMENT,
summary TEXT,
date DATETIME,
PRIMARY KEY(ID))
In this example I have capitalized all of the MySQL command terms. This is primarily done for readability. "ID" is the name of the first column and is traditionally capitalized as well.
"tablename" is the name of your first table and can be anything you want, but I would avoid spaces to avoid possible confusion later on. I have separated the code above onto separate lines for readability.
On the second line we begin creating the columns. There will be 3 altogether, but you can add more or remove them or alter them later as you see fit. The first row is called "ID" "INT" is of type integer. As a side note, you can have Tinyint, or Bigint. INT is about 10 digits long and is more than enough for our purposes, which is to number your rows. Not Null means there will always be a value there. "AUTO_INCREMENT" means that every time you add a row to the table it will automatically write in the next number, 1, 2, 3, etc. Nearly every table has a row named "ID" to number your rows.
The next column we will name "summary", but this can be named anything, just like ID. This table will be given the attribute of "TEXT", if each field of each row is the size of a novel you may want to use BIGTEXT instead. This is your main content.
the third column is called "date" with the DATETIME attribute. This means that it will store a time for each of your rows of data. I like to use this column as a way to date when a row was created. I have a second one that I like to also use to document when a row was last updated.
The last column we state that ID is a PRIMARY KEY, so as not to have two rows with the same ID#.
There is another way to create a table. In phpmyadmin select a table and then at the bottom of the page you will see an option to create a table that way and just follow the steps.
Next up we will put some data into your table, but I'll wait and see if you have any questions at this point.
james438
12-23-2010, 12:03 AM
fastol1, sorry, but that is not quite what Ryya is looking for. It is handy, but only as a possible extension to what Ryya is working on. I looked through the other videos and could not find anything along the lines of what is being asked about.
Ryya, what sort of data are you wanting to be searched? Can you give some details on how your search program will be used?
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.