views:

32

answers:

3

i am new to php, html and js.I am trying to make a website using php, html and js and what i want to is search. actually i have a database which is storing name of videos and their URL and i want to match entered text with name of video in db. for example if someone enters arith in search text box all names having arith word in them should be searched like arithmetic etc. how can i do this??

+1  A: 

Assuming your DB is MySQL you're looking for the LIKE command: http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html

Your query would be something like:

$res = mysql_query("SELECT id, name, url FROM videos WHERE name LIKE '%arith%'");

The % character is a wildcard pattern matcher saying "anything can be here". If you wanted to match anything beginning with the search term just remove the first wildcard matcher:

$res = mysql_query("SELECT id, name, url FROM videos WHERE name LIKE 'arith%'");
Cryo
A: 

The first thing you need to do is tell us what database server you're using, as you're working with PHP I'll guess that your web hosting is "LAMP" (Linux, Apache, MySql and PHP) so here's a selection of links to tutorials for using MySql from PHP:

And specifically you're looking for the LIKE/% operator to use in your query, so take a look at:

An example of the query in PHP would be:

$matchingvidoes = mysql_query("SELECT `name`, `url` FROM `videos` WHERE `name` LIKE '%arith%'");
Rob
A: 

If you're using a MySQL database as I assume you are, you might start with looking at MySQL fulltext search. I started out with examples from the comments and developed my fulltext searches from there.

Xorlev