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...
Search Engine
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
SELECT * FROM `table` WHERE `Name` LIKE '%$name%'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
i know, i've tried that, but i don't know what else to put in the code....feyd wrote:is the general way it would be done in most cases.Code: Select all
SELECT * FROM `table` WHERE `Name` LIKE '%$name%'
the LIKE keyword is the operative part in this instance.
http://dev.mysql.com/doc/refman/4.1/en/select.html
-
stuffradio
- Forum Newbie
- Posts: 14
- Joined: Tue Jan 03, 2006 2:33 am
what you need is:
i think is something like this
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>
";
}-
Maluendaster
- Forum Contributor
- Posts: 124
- Joined: Fri Feb 25, 2005 1:14 pm
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