Witam.
Technologia której używam opiera się na takim szablonie.
<script src="EBSetupEx.js"></script>
<script>
class myApp{
constructor(){ /* kod stronu w JS*/}}
setTimeout(function(){my_new_shining_app = new myApp();},300);
</script>
kiedy generuje to za pomocą php skrypt się wykonuje 2 razy.
np.
<script src='EBSetupEx.js'></script>
<script defer>
<?php
echo "class app{constructor(){ElementBuilder.setWorkplace();";
echo "window.top.myApp.log_window.add_log('Error creating table ');";
$currentDate = date('Ymd');
$currentTime = date('His');
$z=$currentDate.$currentTime;
echo "window.top.my_table='$z';document.documentElement.owner=window.top;";
$servername = "****"; // Replace with your MySQL server name
$username = "****"; // Replace with your MySQL username
$password = "****"; // Replace with your MySQL password
$database = "****"; // Replace with the name of your MySQL database
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
echo "document.body.innerHTML = '<label style=\"font:20px italic arial,serif;color:red;height:50%;width:70%;\">Not connected!</label>';";<br>
die("Connection failed: " . $conn->connect_error);
} else {
echo "document.body.innerHTML = '<label style=\"font:20px italic arial,serif;color:red;height:50%;width:70%;\">Connected!</label>';";
}
$kkk = "";
$sql = "CREATE TABLE `" . $z . "` (id INT PRIMARY KEY AUTO_INCREMENT,name VARCHAR(50) NOT NULL)";
if ($conn->query($sql) === TRUE) {
$kkk = $kkk." document.body.innerHTML += '<label style=\"font:20px italic arial,serif;color:red;height:50%;width:70%;\">Table created<br> successfully</label>';window.top.myApp.log_window.add_log('Table with id $z created successfully');";
$kkk = $kkk."window.top.my_table = '$z';";
$kkk = $kkk."window.top.myApp.info_window.window.buttons[0].innerText = '$z';";
$kkk = $kkk. "window.top.myApp.info_window.window.buttons[1].childNodes[0].value = '$z';";
} else {
$kkk = $kkk."document.body.innerHTML = '<label style=\"font:20px italic arial,serif;color:red;height:50%;width:70%;\">Error creating table: " . $conn->error . "</label>';window.top.myApp.log_window.add_log('Error creating table $conn->error');";
}
echo $kkk;
$conn->close();
echo "}}setTimeout(function(){myApp = new app();},300);";
?>
setTimeout(function(){myApp = new app();},300);</script>
Pytania 2 - czemu tak się dzieje i czy może się uruchamiać to regularnie?
Wynik działania po jednym przesłaniu formularza to
2023-7-9 10:46:15 Table with id 20230709104614 created successfully2023-7-9 10:46:15 Table with id 20230709104614 created successfully
Zdublowane za każdym razem.