Answer the question
In order to leave comments, you need to log in
Solution or how to implement site search from a list in a file?
Hello everyone, we need a search for a site with the ability to select and upload a file, let's say excel with two columns, in the first id of the product, the second is the number and delivery of goods from the list inside the site, how to implement? Or maybe there is a solution?
Answer the question
In order to leave comments, you need to log in
Here you need to start with the table schema in the file and the table schema in the database. And so the algorithm is something like this:
1. A file loader is written (or a ready-made one is taken )
2. A parser of the loaded xls file is written (or a ready-made one is taken )
3. The parsed parameters are substituted into the request to the database.
There are two options:
$mysqli = new mysqli('localhost','root','','test'); //соединение с уже созданной базой
if ($file = fopen("base.csv", "r")) { //прочтение файла .csv
while(!feof($file)) { //построчное чтение в цикле
$line = fgets($file);//присвоение прочитанного файла в переменную.
$line = explode(';',$line); //распиливаем значения по точке с запятой
$id = $line[0]; //первое значение до точки запятой
$url = $line[1]; //второе значение после точки запятой
$sql = "INSERT INTO `screen` (`id`, `id_site`, `url`) VALUES (NULL, '$id', '$url');"; //готовим к добавлению в базу новых значений
$mysqli->query($sql); //выполняем запрос в базу
}
fclose($file); //заканчиваем чтение файла
}
$mysqli->close();//закрываем соединение с базой
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question