1

I want to setup code that does this: (* is wildcard)

SELECT * FROM * WHERE * CONTAINS '$search-query';

What MYSQL code can I use to acheive this.

Sam Clark
  • 429
  • 3
  • 7
  • 12

1 Answers1

2

There is a project called anywhereindb which can do what you want.


I am not going to create a full solution, its going to take a long time, but, I am going to create an example of what you would called

SELECT * From `tablename` WHERE * CONTAINS `$search_query`

First, lets extract the fields

$fields = array();
$query = "SELECT * FROM `yourtable` LIMIT 1;";
$result = mysql_query($query);
while ($i < mysql_num_fields($result)) {
    $info = mysql_fetch_field($result, $i);
    $fields[] = $info -> name;
}

Now prepare your query

$query = "SELECT * FROM `table` WHERE";
foreach($fields as $index => $field) {
    $fields[$index] = $field." CONTAINS '$search_query'"
}
$query .= implode(" and ", $fields);
//Finally query
$result = mysql_query($query);
Starx
  • 77,474
  • 47
  • 185
  • 261
  • That won't work. I need something I can directly implement into my site. I want to stick strictly to PHP. I need something I can run directly through the mysql_query command. – Sam Clark Apr 13 '12 at 00:57
  • @SamClark, Check the update. Thats the best I will give to this question. Please dont mind. – Starx Apr 13 '12 at 01:16