Page 1 of 1

Search Engine

Posted: Sat Jan 21, 2006 9:20 pm
by Maluendaster
Hello, i've tried to make a script to search my site with no success... I've read like 100 tutorials but i can't make it work or the result is not what i've espected... I'm still a newbe in this, so if anyone can help me , i will thank you a lot....

Here's what i have been trying to do...

I have a table with 3 fields : ID , Name , Url , Image

I need a script that can search the "Name" , and the results came up with something like this :

For Example I search for "Amy"

Results (Found X for Amy) :
Amy Cooper
Amy Ried
Amy Sue
....
etc.

And each result are linked to their specific URL

Did i make myswef clear?? i hope so...
Ok, that's all, i'll really appreciate it if someone can help me on this...

Posted: Sat Jan 21, 2006 9:54 pm
by feyd

Code: Select all

SELECT * FROM `table` WHERE `Name` LIKE '%$name%'
is the general way it would be done in most cases.

the LIKE keyword is the operative part in this instance.

http://dev.mysql.com/doc/refman/4.1/en/select.html

Posted: Sun Jan 22, 2006 2:20 am
by Maluendaster
feyd wrote:

Code: Select all

SELECT * FROM `table` WHERE `Name` LIKE '%$name%'
is the general way it would be done in most cases.

the LIKE keyword is the operative part in this instance.

http://dev.mysql.com/doc/refman/4.1/en/select.html
i know, i've tried that, but i don't know what else to put in the code....

Posted: Sun Jan 22, 2006 2:23 am
by stuffradio
lol, hmm send me your MSN maybe I can help you?

Posted: Sun Jan 22, 2006 7:07 am
by duk
what you need is:

Code: Select all

SELECT ID , Name , Url , Image  FROM `table` WHERE `Name` LIKE '%$name%'

Code: Select all

$sql = "SELECT ID , Name , Url , Image  FROM `table` WHERE `Name` LIKE '%$name%'";
$exec = mysql_db_query(DB_NAME, $sql);

// - ====================== -
// the table to organise the info
echo"
<table border=1>
<td>NAME</td><td>URL</td><td>IMAGE</td> <tr>
";
while ($result = mysql_fetch_array($exec)) {

// - ====================== -
// the ouput will be in the table in the
// correct columns
echo "
<td><a href=\"link?id=$result['ID']\">$result['name']</a></td><td>$result['url']</td><td>$result['image']</td> <tr>
";

}
i think is something like this

Posted: Sun Jan 22, 2006 12:17 pm
by Maluendaster
i get this error :

Code: Select all

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/planmal9/public_html/searched.php on line 19