Search Engine

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Search Engine

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post 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....
stuffradio
Forum Newbie
Posts: 14
Joined: Tue Jan 03, 2006 2:33 am

Post by stuffradio »

lol, hmm send me your MSN maybe I can help you?
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post 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
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post 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
Post Reply