Tips On Creating Your Own Search - PHP/MySQL Integrated search on your site
vistal
Oct 27 2005, 05:43 AM
I'm not a professional web developer but I've learned a lot since I used Macromedia Dreamweaver. The latest version 8 supports PHP 5. If you select PHP as your working language, you can use this software to automatically add dynamic content to your website with MySQL as a requisite.
If you have a MySQL database containing records like a songs information database, then you might probably not be able to add a good search page to your website which will search records in the database. I faced the same problem, but now I'm able to create one sophisticated database search. I would like to share my knowledge with you. But it's not possible for me to start with a certain point here. I would like you people (interested in creating a search page) to post your problems here & I'll definitely help you.
You can see the search which I created on my past website as a sample of what I'm talking about. Click here to visit that. One thing I used to look for was a search script which could also bold the search terms in the search results, but couldn't find that. Now you can see on my past website that it also bolds the search terms in the search results.
As a demo, put the keyword The in the search box & you'll find out how cool search results page you'll experience there.
I would welcome any queries & suggestions regarding this discussion.
I think nobody's getting time to initiate. Ok then! I start it my self.
Well! of course the search will be implemented on an existing database, so the first thing you need is a database. It may contain any sort of data, but lemme make it a music database.
You must be familiar with MySQL & its implementation to understand what I am going to say below. And if you aren't, then it's better to jump to any other topic. (You may ask any question as well...)
Designing database is not any task. It would become easy if you mess up all the data in a single table, but of course, it would heavily increase the size of your database. Try to divide your data in different tables for optimum performance. For instance, if you are creating a database which would be used for displaying songs available to be downloaded, you need at least 5 tables in my point of view; artists, album, genre, songs, links. The tables must be related to each other by ID keys, like albums table would contain a column of artistID whose value will be the value in the ID column of artists table, which will show that a particular album belongs to a particular artist.. And same applies to other tables likewise.
Uptil this point, it was an overview of how the database should be sorted out. Now the records should be created. In the next reply to this post, I'll post a sample code to let you understand how the things should go.
Below is a sample MySQL querying performed in PHP to a pre-defined MySQL database. Just look at the code below to get an idea for fetching the results independently from the tables.
CODE
[font=Courier] // SQL Query
// ***Songs*** // Any keyword Songs (Songs) using $originquery mysql_select_db($database_connMembers, $connMembers); $query_rsSongs = sprintf("SELECT * FROM songs WHERE title LIKE '%%%s%%' ORDER BY title", $titlevalue); $rsSongs = mysql_query($query_rsSongs, $connMembers) or die(mysql_error()); $row_rsSongs = mysql_fetch_assoc($rsSongs); $totalRows_rsSongs = mysql_num_rows($rsSongs);
// ***Artists*** // Any keyword Artists (Artists) using $originquery mysql_select_db($database_connMembers, $connMembers); $query_rsArtists = sprintf("SELECT * FROM artists WHERE name LIKE '%%%s%%' ORDER BY name", $titlevalue); $rsArtists = mysql_query($query_rsArtists, $connMembers) or die(mysql_error()); $row_rsArtists = mysql_fetch_assoc($rsArtists); $totalRows_rsArtists = mysql_num_rows($rsArtists);
// ***Albums*** // Any keyword Albums (Albums) using $originquery mysql_select_db($database_connMembers, $connMembers); $query_rsAlbums = sprintf("SELECT * FROM albums WHERE title LIKE '%%%s%%' ORDER BY title", $titlevalue); $rsAlbums = mysql_query($query_rsAlbums, $connMembers) or die(mysql_error()); $row_rsAlbums = mysql_fetch_assoc($rsAlbums); $totalRows_rsAlbums = mysql_num_rows($rsAlbums);
Now, the art goes with you, i mean how you place your code in your page to look good is totally upto you.
I've left almost every thing after that code in this discussion which would have to be used to display the search results, because it depends on how you want it to look like.
Finally below is the code to BOLD the search keywords in the search results. You have to somehow integrate this code in to your page, so that each result is processed through this code.
If you are comfortable with PHP, you will surely understand the simple logic which I myself created using a bit of built-in PHP functions.
The if-else statements ensures that all the matches in the record whether they be in capital letters or small letter must be processed for Bold.
The variable $keywords below in the code is for that search terms which user entered in the search box. The rest will be explained by the code itself.
CODE
[font=Courier]<?php // Bold $cnt = substr_count($keywords, " "); // $cnt is the number of words in the query $val = explode(" ", $keywords); // $val is an array to store all the words separately
str_replace($search, $replace, $subject); // $search is the text to be replaced // $replace is the text which replaces the $search text. // $subject is the text which contains $search text.
} ?>[/font]
I hope it helped you a lot. But if you feel uncomfortable with any statement, feel free to post your problem. I'll try my best to answer you. That's it for this reply to my own topic.
Well, you should keep this thing in mind that your user is going to enter any value in the search terms & your code should be able to process or handle all such requests. For example when you are querying the MySQL server, and if you use the values in the MySQL command from a variable, so you must ensure that the variable doesn't contain any apostrophies in it, else the result could be very unexpected & the next results page will seriously show off that you're a poor programmer.
Then your search form should not make a user get in to trouble, like there's a lot of options like, search in artists or search in albums or search in song titles or like that.. Rather if the user enter any keywords, your code should automatically search for all the possible matches in artists tables & in albums table & in songs tables & then display the results separably without effecting the look of your page.
Another best method by which your website visitor will be able to save time is that if he/she founds some pre-defined searches in a corner, and if the keywords are the same he/she was going to enter in the search box, then a direct click to that keywords link will surely solve the problem. Keep track of the entered keywords by adding some code to your page & then display them on the main page of your website as a separate source.
Now, the point raises which form method to be used. Of course, you must use GET method, because this is how you'll be able to provide the direct search links for the most used keywords.
And, I think, all these things would perfectly make up a complex & effective database search system. I used songs information database as an example here, but the tips n tricks may be followed for any type of database. Hope, you get my point.
Notice from wassie:
Plz put all posts you made about 1 thing in 1 post. and code the queries
Hello, my name is Derek and I am in the process of creating a CMS. My CMS will be slightly different
than most, because I am creating it for business purposes. I own a business, Black Development &
Produktionz, LLC. and I am creating all of my own services that I will need, such POS (web based to
be integrated with virtually any OS), a scheduling system (for appointment and so that my client
will be able to schedule based on open time slots), an emailing system (which I know will require
more than effort than a normal CMS because it will depend on hosting and so forth), ....
Creating a good website, How?! I looked at many forums, searching on now to create a good
website, by good I meant good website interface. For example, Trap17 have this amazing flash header,
and nice design… I searched and searched, I found that many people started with a photoshop
picture, then they make it come true by requesting a website coder (A.K.A. Programmer) to code the
whole website for it. If, I said if, I were good a art, I can design a good nice picture off
photoshop, and I know how to code, does that means I can make a good website? Please post any ....
Hello, Im going to set up a simple website to use with my buddies. A main page where I can update
from time to time and a forum are all I need. I know WYSIWYG builders, ftp uploaders and forum
moderating. Im thinking of using phpBB since it's free and seems simple and reliable, right?
My question is can I build the forum on my local computer then upload to hosting service? The
readme.txt recomends to install online in host machine. And this is what I need to do, right?
-build an index.html with WYSIWYG, upload it to main folder of host. -create a folder in the....
Hi guys. I want t know if it is posible to have so many entries for one object in a field in MySQL.
I know my question may not be clear because I lack in terminology but pliz try and help. What I want
to do is for axample have a database of my clients with the following fields for every client:
fname, lname, more than one photos, contrubutions(comments, jokes, testimonials posted) etc. I want
to have the things like the photos in the same field but they have to be unique so that my php code
can deal with them individually llike they are coming from different fields.....
I hope I am on topic here (It does have to do with web design, after all). I have noticed that in a
MySQL database, the 'id' field just keeps its numbers for every record, with the backdraw
that, whenever you remove (a) record(s) from the table, you get your list numbered as eg.
1,5,6,7,12,25 etc. This makes it a bit difficult of keeping track of the number of records in your
table. Is there a way of achieving (either in PHPMyAdmin or through the use of PHP) that the id
field in your table gets sort of 'refreshed and updated' so you have a clearer view....
Ok this is my idea: I am making a website about anime. Its function is add anime, review anime,
search anime, anime information. Users can make a profile. People can make a profile which they can
edit to theire likes with html to give it a fancy look.(this is what my problem is about) What i
would like to know is how can i accomplish this. I already have the database for the anime titles
etc ready, the only thing that needs to be done is the profile section. If you have any tutorial,
tip or guide i would really really appriciate it. Thx in advance. ....
Alright so there are many topics out there of how to make a website that everyone will love and want
to go to, but I can't seem to find any about how to make a website that people will hate and try
to run away from, so here are some pointers for those who are trying to make the worst website:
Step one: COLORS Be sure to use a vivid and bright background color, and a non-noticeable text
color. Nothing wakes people wake up more than a florescent yellow background with white text. Make
people work to try to read your website. After all, you have some great content....
Hi, I am creating a website in php and using a mysql database to store the data. I want to store
time data in the database. My question is what is the best datatype I should use and how do I read
the time from the database and format(display) it using php ?....
Well, I'm working in a fan club site, this is like our 5° site because every host in which
we've been in always change something and the site stops working. The site is a Black Eyed Peas
fan club site, it already has profiles (with gallery and comments box) for each
user,forum,chat,videos,gallery,lyrics,downloads,bios of the members of the BEP, but I think that the
site need something else. Please gimme some ideas to make this site the best! /biggrin.gif"
style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />....
im a noob when it comes to web html to design web sites, can some one tell me where to find a good
website that has good tutorials on how to use web html?....
I want to open a shopping portal in my site which will do the following: take the information from
the visitor what good they want to sell then directly post it on my site What script i choose that
will suit the website of mine could any body tell me....
This is my new template I'm going to be using for my new site. It took me 3 days to do. I spend
day 1 drawing it up sorry I cannot upload my draft sketch as my scanner is not working. The next 2
days I spent drawing it up in photoshop. The colours are kinda generic I know but thats my style. I
cant seem to create anything other then grey toned things. I think adding some decay onto the panels
will give it some depth something my style of drawing lacks. The panels - I like as many panels as
I can so I went with the 3 column layout and extra 2 side header panels for ....
I found a nice program which allows you to put quizzes on your web site. You can design your own
questions, set the layout of your page, and there is also a possibility of having the results
emailed to you. It further offers a facility to store the results and all that, all you have to do
is put a link in the program, telling it which page takes care of that. However, when I look at the
HTML code the program generates, I see that most of it is written in Javascript. Obviously, it also
uses variable names, but as I don't know any Java, I was wondering if those variab....
hi frnds everyone want to keep an eye on their site traffic. histats is a really great one i found
with gives site stats for free. it have many amazing features. visit www.histats.com i am
sure u will like it... this is my first post so excuse me if my post have any mistakes....
:rolleyes:Use great graphics an good color which attracts the users/views eyes an capturers there
attention which cuases them to view your website if its good enought they'll register. Also use
good images, links an have blogs an forums also start a referring website such as like this: Visit
this site and know all the info about the CHITWAN http://hamrochitwan.com Some thing like that
would get more users depending on if the items in your shop are GOOD maybe like moderator for a week
costing 100 referals or somethink. /blink.gif" style="vertical-align:middle"....
In my MySQL table I would like to use one text field which can contain lots of text. What I want to
use it for is for student records, and I want to be able to add to it without destroying what is
already there. I want the field to contain something like: ****03/11/2007**** Chopin prelude No 9:
small problem bars 12-15. Advice given on how to practice. ****10/11/2007**** Problem in Prelude
overcome, piece successfully completed. New piece set: Beethoven Sonata No 1, movement 1. etc. This
is of course just an example, but that is how I want to set up my student records....
If I wanted to use an ID field which automatically increments when data are addad, but displays the
ID as a 5 figure number, which data type would I have to use? I would want a type that assigns a
number to a record in the format "00001", "00002", etc. However, when I use "int" as datatype, it
only displays th field contents as "1", "2" etc. So, which data type could do the job for me? i do
not need a decimal point or anything, just an id that displays in 5 figures, including the leading
zeros. Thanks in advance.....
I was wondering how I could solve a small problem. I was told that some people see accented and
umlauted letters (such as " é " and " ë ") as question marks (" ? ") on my website. I come across
the same thing sometimes when looking at websites which use non-English characters. Funnily enough,
the other day, I looked at a site and the apostrophy ( ' ) was also shown as a question mark.
That is a very common character usually, I would think. I thought it had something to do with the
character encoding settings, and let me also mention I use Mozilla Firefox as my brows....
http://jlhaslip.com/snews/ Have a look, please. Forum link is top of the left-hand sidebar. AEF
Forum software can be downloaded from http://anelectron.com sNews CMS can be downloaded from
http://www.snewscms.com/ The link above shows the two combined using a Wordpress Theme as a base
for the layout (modified), and integrates a centred, horizontal Unordered List as a Navigation Bar
below the header, courtesy of Stu Nicholls at http://cssplay.co.uk I need to begin coding a
Login integration script next. /smile.gif" style="vertical-align:middle" emoid=":)" bo....
Hey guys, Im have a gta type of site, and need some help with it. I am using HTML, and am using a
pretty basic template, and cutenews. My banner looks funky, and I do not know how to put
information on the left hand side, even though my right hand site has links and stuff. The link is
gta-source.net/index.php make sure you go to that link or it'll redirect to the forums. So
please if anybody can help me I would appreciate it.....
Hi. I need some help with this website that I am going to make I am making it somewhere else but I
am going to use my Trap17 hosting service as the media so if there was a game on my website I would
put a link and it would link back to here and would show a black background and the media game, or
video. Could anyone tell me how I would do that? Only the background code. But even before that I
need to uninstall Joomla. Let me say first that I have not idea how to find my way through Traps
control panel? Thanks in advance.....
Well thanks to Trap17 my web site is up and running again. I have most everything put back, just
need to do a fair amount of fine tuning. I have questions on a couple topics before I do much more
on it. Which is best for links on your site that leave your web site, to have them open in a new
browser window or just go direct to the site? I heard somewhere that they should open in a new
window, as you don't want people to leave your site, but do you all find the new windows to be
annoying? And which looks best, text that scrolls and the background doesn't m....
well, i don' t have a site yet, but about 6 months ago i made a template, with flash buttons and
all, with sound and everything i was so proud so i tryed to put em on there with a special code u
needet or something ,so i did, but i got blank images,, i even tryed uploading it on the site it
didn't work, so i asked around they said u can' t install them on a cpanel, u need ftp, so i
downloadet the program needet and i got stuck there, so basicly how do u do that,and could some1
help me out how to get it working on a cpanel....
Hi, I've been trying to look for ways to run an auction site thats easy to set up and I saw
drupal... Is there a way to run an auction site using drupal?? If anyone of you know how to do it
plzz help me! I've tried to look through google but not getting any help! I want to make
an auction site which will be able to take few types of product posted by the users and let other
users log in to bid for the price! Is there a way to do so?? And if anyone of you know an
easier way to go about doing it please help me! even if its not drupal but something ....
I have seen this site before.The site is simple.there are a box that you can put a url link then
press enter you can see the code of the page (see everything include meta,comment...),even it is
written in php,asp... If anyone know this site,please let me know(I have format my computer,so I
lost it).thank you. ....
I started writing an article about this for an article site I had just joined. It was done! I
wrote so much! I was so thrilled! I hit "Submit!" And as it turned out, it had timed out
and the entire page reset. My face was probably priceless but so was my utter rage. So I've been
careful about what I write since then. I have a Notepad document open as I type. And then I make
several threats and continue writing. But back to the point. Hosting This one's simple. Dear
god, if you ask me questions about this, I will scream very loudly. But seri....
Hi buddies . I just got free Web Hosting by Trap 17 , it is a real great pleasure for me. Now there
are several problems in my mind regarding to CREAT my own FIRST website. * Which software should
i use for building my website ? * I want to know how to show the IP of the visitor on the welcome
page of my site? * I want to place e-messenger on my site , how to place it ? * I want to create
different flash and java effects on my site how to create them? As in my earlier post i told that i
just start using computer so please help me to solve my problems described a....
Has anyone tried using the excel import function that comes with phpmyadmin
http://www.phpmyadmin.net/home_page/ - it does not require any additional plug-ins or scripts and
is fairly straightforward to use. In phpmyadmin, if you click on the database table which you wish
to import the data to , there is a link on the bottom left corner which says "insert data from a
text file into the table" - although it says text file it still can be used to import an excel file.
When you click on this link you will be taken to a page where you will be asked for the file name
(the....
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE
forum, Create your own topics, Ask Questions, track topics, setup
subscriptions & notifications and Get a Free Website w/ Email and FTP.