0

I am using this code to find out if there is a field in the column "website" that matches $string:

$get_results = $wpdb->get_results($wpdb->prepare(
     "SELECT * FROM yc_customers WHERE website LIKE %s LIMIT 10", 
     "%{$wpdb->esc_like($string)}%"
));

This works but I would like to figure out if there is a field in ANY COLUMN that matches $string.

I thought I could just use WHERE * but this is not working for me.

rap-2-h
  • 30,204
  • 37
  • 167
  • 263
Reza Saadati
  • 5,018
  • 4
  • 27
  • 64
  • you can export the database and search through it using a text editor, see [here](http://stackoverflow.com/questions/5350088/how-to-search-a-specific-value-in-all-tables-postgresql/5350405#5350405). – IROEGBU May 26 '15 at 17:40
  • 1
    Possible duplicate of http://stackoverflow.com/questions/10656529/sql-where-any-column-equals-a-value (basically it's getting the column list and then building the query using that) – IT goldman May 26 '15 at 17:14

2 Answers2

0

As far as I know the only place a "wildcard" for specifying fields is allowed is in the SELECT.

Uueerdo
  • 15,723
  • 1
  • 16
  • 21
0

Nevermind, I found myself a solution:

$get_results = $wpdb->get_results($wpdb->prepare(
    "SELECT * FROM yc_customers WHERE website LIKE %s OR receiver LIKE %s OR email LIKE %s LIMIT 10",
        "%{$wpdb->esc_like($string)}%",
        "%{$wpdb->esc_like($string)}%",
        "%{$wpdb->esc_like($string)}%"
));
Reza Saadati
  • 5,018
  • 4
  • 27
  • 64