for example.. in one column it has "test1, test2, test3, test4" .... when i search for test1... i only want rows the word 'test1' in them specifically.

$search = test1

i've tried LIKE %$search% but it get's all rows with the word 'test' in it... i want only rows with the word 'test1' in it.

Recommended Answers

All 3 Replies

We need more information to be able to help you in a specific manner, but the query statement would generally look something like:

mysql> SELECT * FROM <database_name.table_name> WHERE <column_name> LIKE 'test1';

This is basic SQL query structure and will apply to any database management system.

Presuming that you are using MySQL, there is a TON of very helpful, basic information available at the MySQL Community web site. Here's a decent starting point for you:

http://dev.mysql.com/doc/refman/5.1/en/index.html

I hope this helps!

/David C.

ok here is a little more information...i'm having a problem, my query should get the result "michael" but instead it returns both results.


name:dave , keywords="test1, test2, test3"

name:michael, keywords="test,test9"

$search="test";
$getfirst =  mysql_query("SELECT * FROM block WHERE keyword LIKE '%$search%' ORDER BY `id` DESC",$this->connect);

OK - that's helpful. Thank you.

If you set your variable $search to be equal to test (which you did in line 1. above)
then indicating that you want MySQL to search for the keyword like '%$search%' . . .

well, that would return both results.

Why? Because when you encapsulate $search (which you set to test) with % at the beginning and % at the end - it will match ANY form of the string text with anything before it and anything after it.

%test% = test1, test2, test3, test, test9, zebratestjayhawk, sillystringtestmessy, testiment, testing . . . etc.

ALL of those (and infinitely more!) = %test%

So, your query is working just fine. You just aren't getting the results you're after.

1) Why are you setting the variable $search to "test" ?
2) Why are you assigning the value "test" to entities that you want to return discreet values?

Thanks!

I hope this helps -

/David C.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.