query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$_GET['table_name']}' and table_schema = '{$_SESSION['db_name']}'"); while ($row = $results->fetch_assoc()) { $column_name = $row['COLUMN_NAME']; if ($column_name == 'record_id') { continue; } else { $name_arr[] = $column_name; $var_arr[] = $_GET["$column_name"]; } } $index = 0; while ($index <= count($name_arr)) { if (strlen($name_arr[$index]) < 2) { } else { $string_1[] = "`" . $name_arr[$index] . "` LIKE '%" . $var_arr[$index] . "%'"; } $index++; } $where_data = implode(' AND ', $string_1); $result = $db->exec_query($_GET['table_name'], ['*'], '', '', '', '', $where_data, "ORDER BY {$_GET['order_by']} {$_GET['order_type']}"); if ($result->num_rows < 1) { echo "
NO RESULTS "; echo "
"; } $db->add_log("USER SEARCHED WITH { " . str_replace("'", " ", str_replace('`', ' ', $where_data)) . " }", $_GET['table_name'], 0); while ($data = $result->fetch_assoc()) { echo "
"; if ($_GET['table_name'] == 'income') { // get client id $invoice_result = $db->exec_query('invoices', ['*'], '', '', '', '', "record_id = {$data['invoices_id']}"); $invoice_data = $invoice_result->fetch_assoc(); // get client name $client_res = $db->exec_query('clients', ['*'], '', '', '', '', "record_id = {$invoice_data['clients_id']}"); $client_data = $client_res->fetch_assoc(); echo " "; } foreach ($name_arr as $colls) { if (strpos($colls, '_id')) { $link_table_name = substr($colls, 0, strpos($colls, '_id')); $link_table_result = $db->exec_query($link_table_name, ['*'], '', '', '', '', "record_id = {$data[$link_table_name . "_id"]}", "ORDER BY " . $link_table_name . "_name ASC"); $link_table_data = $link_table_result->fetch_assoc(); echo " "; } else { ?> "; echo "
"; }