Answer the question
In order to leave comments, you need to log in
PHP. How to implement waiting for the execution of a function?
Good afternoon. Can you please tell me how to implement the waiting for the execution of the function?
There is a code:
<?php
require 'ex/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
$i = 2;
do {
$url1 = 'https://img1.goodfon.com/original/1920x1080/b/c9/pole-nebo-gorizont-peyzazh.jpg';
$url2 = 'https://get.wallhere.com/photo/1920x1200-px-nature-1054070.jpg';
$url3 = 'https://cdn.wallpapersafari.com/70/76/AnNVBR.jpg';
if (isset($_GET['test'])) {
echo 'Вы нажали на кнопку: ' . $_GET['test'];
$cell = 'F'.$i;
$url = $_GET['test'];
$inputFileName = './ex/e.xlsx';
$spreadsheet = IOFactory::load($inputFileName);
$spreadsheet->getActiveSheet()->setCellValue($cell, $url);
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save("./ex/e.xlsx");
echo "Я внёс!";
$i=$i+1;
}
echo <<<HTML
<html>
<head>
<style>
img {
height: 100px;
width: 100px;
}
</style>
<script type="text/javascript" src="js/jquery-3.2.1.js"></script>
</head>
<button onclick="set_mode_view(this)"><img src="$url1" alt="Кнопка «button»"></button>
<button onclick="set_mode_view(this)"><img src="$url2" alt="Кнопка «button»"></button>
<button onclick="set_mode_view(this)"><img src="$url3" alt="Кнопка «button»"></button>
<br/><br/>
<div id="test_value"></div>
<script>
function set_mode_view(element)
{
$.ajax({
url:'test4.php',
data:{test:element.firstChild.currentSrc},
success:function(data){
$('#test_value').text(data);
}
});
$(".current-msg").html("");
}
</script>
</html>
HTML;
} while ($i < 10);
?>
Answer the question
In order to leave comments, you need to log in
It is necessary to clearly separate the client and server parts. "Cycle" should be on the client ... on the server is also possible, but it's a crutch.
The server should accept requests - empty, with the selected image and position id.
With an empty request, it issues a client shell with scripts and pictures (the position is taken by default as 1, those pictures from 1 to 3 are given), when requested with arguments, it makes changes to the exel file and issues the following pictures, taking into account the current position, if there are no more pictures, it issues your text that there are no more pictures.
The client side should contain a div for images (by default, images will be loaded using 1 position, on the server side), js variable of the current position (by default 1, set on the server side when sending the client shell), jq image selection event and ajax function for processing it (when choosing ajax sends the selected image and the current position, in return it receives the images that need to be written to the div for images with content replacement).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question