Forum Moderators: coopster

Message Too Old, No Replies

Search Matters

how to count that matches in the search

         

camilord

6:20 am on Jun 2, 2007 (gmt 0)

10+ Year Member



can anybody help me abut this...

my method in searching in the database is...

$keyword = 'test';

$result = mysql_query("SELECT * FROM items WHERE item_description LIKE '%" . $keyword . "%' OR item_name LIKE '%" . $keyword . "%'");

now, my problem is, how to count that matches on that rows in the database...

camilord

6:23 am on Jun 2, 2007 (gmt 0)

10+ Year Member



i think my words wasn't enough..

i mean, how many words that matches on every single row from the database.

lets say under the query above in description field:

ROW 1: "test odasp doapid test ados oidaps odas"
ROW 2: "odasp doapid test ados oidaps odas"
ROW 3: "test tes test odasp doapid test ados oidaps odas"

so the result must be in row 1 = 2, row 2 = 1 and row 3 = 4

IndiaMaster

6:35 am on Jun 2, 2007 (gmt 0)

10+ Year Member



I think you have to retrieve the rows first and then loop through the result set and count the no. of matches in each row.

I cann't able to think anything about it.

Can anyone other can?

camilord

7:13 am on Jun 2, 2007 (gmt 0)

10+ Year Member



hehehe.. i already do that.. but if possible, in mysql query stage, its been counted already all the possible matches. :)

but i think there's no solution for this.. better move on..

thanks anyway.. :)

barns101

1:07 am on Jun 3, 2007 (gmt 0)

10+ Year Member



You need to use mysql_num_rows()


$keyword = 'test';

$result = mysql_query("SELECT * FROM items WHERE item_description LIKE '%" . $keyword . "%' OR item_name LIKE '%" . $keyword . "%'");

$rows = mysql_num_rows($result);
echo "There were $rows rows.";