-1
I have the query used in WP and it causes an error when I use OR, follow the example of use:
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: He makes a mistake in a ditch 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 the part of the code, line 221 to 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;
}
Please show us the table and the error that displays.
– Mauro Alexandre
If this string is formatted with
sprintf()
he will complain that missing an argument, can place the call of this query?– rray
added the call of the consultation tb
– Alan PS
Query looks good. Try printing your query in php and make sure it’s up to you
– MiaSanMia
The error is that only searches the lines with name and ignores the email?
– Ricardo Moraleida
@Ricardomoraleida dei 2 edits up with 2 functions, error is in line 237 of code
$this->found_data = array_slice($this->example_data, (($current_page - 1) * $per_page), $per_page);
– Alan PS
no, it gives an error on line 237, php error, does not appear search results
– Alan PS