File "table_06.php"
Full Path: /home/analogde/www/Outlook/Fusion/Table/table_06.php
File size: 5.44 KB
MIME-type: text/html
Charset: utf-8
<?php
include("calendrier_generation.php");
echo " aaaa Generation d'uune fenetre temporelle ... ";
echo "<br>";
$liste_annee = array("2024");
for( $i=0; $i < count($liste_annee) ; $i++)
{
////$table = creation_table_annuelle($liste_annee[$i]);
$listing_jours = calendrier($liste_annee[$i]);
echo "<pre>";
print_r($listing_jours);
echo "</pre>";
}
echo " ----> " .count($listing_jours);
echo "<br>";
//print_r($listing_jours[0]);
$nb_elements = count($listing_jours[0]);
$DateArray = array();
for( $i=0; $i < $nb_elements ; $i++)
{
$pieces = explode("_", $listing_jours[0][$i]);
$DateArray[] = $pieces[0];
//echo "---> " .$pieces[0];
//echo "<br>";
}
echo "Liste des dates" ."<br>";
echo "<pre>";
print_r($DateArray);
echo "</pre>";
// creation du tableau
$site = $_SERVER["SERVER_NAME"];
if( ($site == "localhost") || ($site == "127.0.0.1") )
{
echo "Mode local";
echo "<br>";
$hostdb = "localhost"; // MySQl host
$userdb = "root"; // MySQL username
$passdb = ""; // MySQL password
$namedb = "task_manager"; // MySQL database name
}
else
{
echo "Hebergeur";
echo "<br>";
$hostdb = "analogdepat.mysql.db";
$userdb = "analogdepat";
$passdb = "Un92pac007";
$namedb = "analogdepat";
}
$con = mysqli_connect($hostdb, $userdb, $passdb, $namedb);
if (mysqli_connect_error())
{
die("Database connection failed: " .
mysqli_connect_error());
}
$create_table = "CREATE TABLE IF NOT EXIST test1
(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL
)";
/*
echo " Query " .$create_table;
echo "<br>";
echo "<br>";
echo "<br>";
$create_tbl = $con->query($create_table);
if ($create_table)
{
echo "Table has created";
}
else
{
echo "error!!";
}
*/
$tableName = "test1";
$result = $conn->query("SHOW TABLES LIKE '$tableName'");
if ($result->num_rows > 0) {
echo "Table exists!";
} else {
echo "Table does not exist.";
}
$con->close();
?>
<!DOCTYPE html>
<html>
<style>
table, th, td {
border:1px solid black;
}
</style>
<body>
<div id="message"></div>
<h2>HTML table</h2>
<form action="javascript:void(0);" id="frmdata" onsubmit="submitFormData()">
<table>
<tr>
<?php
//$array_val = array("A", "B", "C" );
for ($i = 0; $i <= count($DateArray)-1; $i++)
{
echo "<th>" .$DateArray[$i] ."</th>";
}
?>
</tr>
<!--<tr> -->
<?php
for($row=0;$row<1;$row++)
{
?>
<tr>
<?php
for($col=0;$col <= count($DateArray)-1;$col++)
{
$indice_row = $row+1;
$indice_col = $col+1;
$indice = "col".$indice_col ."-" ."row".$indice_row ;
?>
<td><input type="text" name = "<?php echo $indice; ?>" id="<?php echo $indice; ?>" /></td>
<?php
}
?>
</tr>
<?php
}
?>
</table>
<button type="submit">Submit</button>
</form>
<p id="display_text"></p>
<p id="debug"></p>
<script>
function submitFormData()
{
// OK
//var element = "col1-row1";
//champ = document.getElementById(element).value;
//alert("plouf " + champ );
let text = "";
var tableau = new Array();
for (let i = 0; i < 22; i++) //
{
var array_col = new Array(1);
for (let j = 0; j < 1; j++)
{
var col = i + 1;
var row = j + 1;
var indice = "col" + col + "-" + "row" + row;
champ_valeur = document.getElementById(indice).value;
text += champ_valeur + "<br>";
array_col[j] = champ_valeur;
//text += indice + "<br>";
}
tableau[i] = array_col;
}
//document.getElementById("display_text").innerHTML = text;
document.getElementById("debug").innerHTML = "Voici le tableau au format string " + tableau.toString();
//////////////////////////////////////
var tab = new Array();
for (let i = 0; i < 22; i++) //
{
var tab_col = new Array(1);
for (let j = 0; j < 1; j++)
{
var col = i + 1;
var row = j + 1;
var indice = "col" + col + "-" + "row" + row;
champ_valeur = document.getElementById(indice).value;
text += champ_valeur + "<br>";
tab_col[j] = champ_valeur;
//text += indice + "<br>";
}
tab[i] = tab_col;
}
//document.getElementById("display_text").innerHTML = text;
document.getElementById("display_text").innerHTML = "Voici le tableau au format string " + tab.toString();
/////////////////////////////////////
//const cars = ["Saab", "Volvo", "BMW"];
//document.getElementById("message").innerHTML = cars;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var JsonString = JSON.stringify(tableau);
xmlhttp.onreadystatechange = respond;
xmlhttp.open("POST", "envoi_json.php", true);
xmlhttp.send(JsonString);
}
function respond()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
alert("Zorro");
document.getElementById('result').innerHTML = xmlhttp.responseText;
}
}
</script>
<div id="result"></div>
</br>
</br>
</br>
</body>
</html>