Answer the question
In order to leave comments, you need to log in
Recommend a platform (engine or plugin) for the online consulting service in directions?
Recommend a platform (engine or similar) for the online consulting service in directions? I want to create an online consultation. Give options for solutions.
Answer the question
In order to leave comments, you need to log in
there is no need to take the code from these internets of yours if there is no understanding of what and how it works/should work.
puff has one of the best documentation I've ever seen in a japanese, with tons of examples.
Do you even understand what your code means?
Don't copy-paste if you don't know the basics.
First, the normal practice is to put the connection parameters in a separate file.
Create a db.php file with the following code:
<?php
//Параметры подключения в БД
$host = "localhost"; //имя хоста
$database = "base"; //имя базы
$user = "root"; //пользователь
$password = "pass"; //пароль
$dbtable = "table"; //таблица
$link = mysqli_connect($host, $user, $password, $database)
or die("Ошибка " . mysqli_error($link));
?>
function search_users() { //объявляем функцию
$query = strip_tags(trim($_POST['query'])); //принимаем данные из формы поиска
if (preg_match('/[0-9]/', $query)) { //задаём условия для поиска (в данном случае совпадения номера или строки
$sql = "SELECT * FROM Users WHERE phone LIKE '%$query%' ORDER BY id DESC"; //делаем выборку в базе по телефону
}
else {
$sql = "SELECT * FROM Users WHERE surname LIKE '%$query%' ORDER BY id DESC"; //делаем выборку в базе по фамилии
}
global $link;
$result = mysqli_query($link, $sql);
$users = mysqli_fetch_all($result, MYSQLI_ASSOC);
return $users; //выводим результат
}
It is necessary in this class to replace the connection parameters with your own, i.e. replace private static $_db_address with private static $_db_address = 'localhost' etc. call everywhere like:
$connect = CConnectionSingleton::getInstanse();
$users = $connect->sql2data('SELECT * FROM users');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question