I have the query used in WP and it causes an error when I use OR, it follows the usage example:
SELECT * FROM ' . $table_ucf . ' WHERE form LIKE "'. $this->form_active.'" AND name LIKE "%s" OR email LIKE "%s"
If I take the condition after the OR works, example:
SELECT * FROM ' . $table_ucf . ' WHERE form LIKE "'. $this->form_active.'" AND name LIKE "%s"
EDIT:
function getDBData(){
global $wpdb;
$table_ucf = $wpdb->prefix . 'ucf';
//var_dump($this->table_search);
if ($this->table_search) {
$like = '%' . $wpdb->esc_like($this->table_search) . '%';
$form_data = $wpdb->get_results(
$wpdb->prepare(
'SELECT * FROM ' . $table_ucf . ' WHERE form LIKE "'. $this->form_active.'" AND name LIKE "%s" OR email LIKE "%s"',
$like
)
, ARRAY_A);
} else {
$form_data = $wpdb->get_results(
$wpdb->prepare(
'SELECT * FROM ' . $table_ucf . ' ucf WHERE ucf.form = %s',
$this->form_active,
'%' . $wpdb->esc_like($this->table_search) . '%'
)
, ARRAY_A);
}
$this->example_data = $form_data;
}
EDIT: It gives an error in a section below the code;
Warning: array_slice() expects parameter 1 to be array, null given in C:\xampp\htdocs\ekantika\wp-content\plugins\ucf\dx.ucf.table.php on line 237
This is part of code, line 221 through line 244
function prepare_items() {
$this->process_bulk_action();
$this->getDBData();
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
@usort($this->example_data, array(&$this, 'usort_reorder'));
$per_page = 50;
$current_page = $this->get_pagenum();
$total_items = count($this->example_data);
// only ncessary because we have sample data
$this->found_data = array_slice($this->example_data, (($current_page - 1) * $per_page), $per_page);
$this->set_pagination_args(array(
'total_items' => $total_items, //WE have to calculate the total number of items
'per_page' => $per_page //WE have to determine how many items to show on a page
));
$this->items = $this->found_data;
}