K
K
kna9992021-09-14 11:54:42
Web development
kna999, 2021-09-14 11:54:42

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

2 answer(s)
A
artloveyou, 2021-09-14
@artloveyou

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.

I
Ilya12345, 2021-09-14
@Ilya12345

There are two options:

  • The first through the database, for example, you pull out the values ​​​​from the Excel and shove them into the database, then look for it.
  • The second option is to convert the excel file to csv and search through js through it.

The first is more preferable because it is faster due to the search through the database.
The second is bad because each user will first load the file, and if it weighs more than 50 megabytes, it will not be so fast, because in order to find the data in the file you need to read it.
Here is the simplest transfer of data from csv to the database:
for example, the base.csv file contained something like:
23; vk.com
24; https://yandex.ru
$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 question

Ask a Question

731 491 924 answers to any question