Forum Moderators: coopster

Message Too Old, No Replies

Search mysql longtext column

mysql longtext

         

WestpointStevens

5:13 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



I have a column in a mysql table defined as longtext data type.

I am trying to search for key words using php.
I know that mysql indexes the first 1k (1024 chars) of data but I can't seem to even search the first byte.

Can someone lend of a hand?

Thanks

coopster

5:38 pm on Dec 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, WestpointStevens.

Indexes and searching are closely related in their relationship as far as performance, but that shouldn't be stopping you from actually finding the data. How are you currently querying the field that it is turning up no results?

WestpointStevens

5:56 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



$sql = "SELECT `id` FROM `Table` WHERE `notes` LIKE '$searchfor%'";

But I think the issue is that a longtext column is stored as binary, not ASCII, therefore not searchable by standard means.

moltar

6:15 pm on Dec 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am not sure if that is what you tried to do, but the code you provided will search for a field that begins with $searchfor. To search for that string anywhere in the field, you need to surround the $searchfor with % sign.

Example:

$sql = "SELECT id FROM Table WHERE notes LIKE '%$searchfor%'";

WestpointStevens

6:44 pm on Dec 16, 2004 (gmt 0)

10+ Year Member



The simplest solution is always the best...

Thanks!