added field for td and hide show identification parts
This commit is contained in:
+42
-11
@@ -246,29 +246,60 @@ while ($row = mysqli_fetch_assoc($result)) {
|
||||
// Connessione al database
|
||||
$conn = mysqli_connect($servername, $username, $password, $dbname);
|
||||
|
||||
// Imposta la codifica UTF-8 per gestire correttamente i caratteri speciali
|
||||
$conn->set_charset("utf8mb4");
|
||||
if ($conn->connect_error) {
|
||||
die("Connessione fallita: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Query per selezionare le righe da duplicare
|
||||
$query = "SELECT * FROM identificationparts WHERE idtrfdetails = '$idtrf'";
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
// Ciclo attraverso i risultati e duplico le righe
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
|
||||
// Imposto il valore di idtrfdetails come 250
|
||||
// Imposto il valore di idtrfdetails con il nuovo ID
|
||||
$row['idtrfdetails'] = $newidtrfnumber;
|
||||
|
||||
// Lascio identificationparts nullo
|
||||
// Lascio identificationparts nullo (sarà generato automaticamente)
|
||||
unset($row['ididentificationparts']);
|
||||
|
||||
// Query per duplicare la riga
|
||||
$columns = implode(", ", array_keys($row));
|
||||
$values = "'" . implode("', '", array_values($row)) . "'";
|
||||
$sql_insert = "INSERT INTO identificationparts ($columns) VALUES ($values)";
|
||||
if ($conn->query($sql_insert) === TRUE) {
|
||||
echo "Nuova riga inserita con successo identificationparts";
|
||||
} else {
|
||||
echo "Errore nell'inserimento della nuova riga: " . $conn->error;
|
||||
// Controllo la lunghezza di article_identificationparts (limite 250 caratteri)
|
||||
if (isset($row['article_identificationparts']) && mb_strlen($row['article_identificationparts'], 'UTF-8') > 250) {
|
||||
$row['article_identificationparts'] = mb_substr($row['article_identificationparts'], 0, 250, 'UTF-8');
|
||||
echo "Attenzione: article_identificationparts troncato a 250 caratteri.";
|
||||
}
|
||||
|
||||
// Preparo la query con prepared statements
|
||||
$columns = implode(", ", array_keys($row));
|
||||
$placeholders = implode(", ", array_fill(0, count($row), "?"));
|
||||
$sql_insert = "INSERT INTO identificationparts ($columns) VALUES ($placeholders)";
|
||||
|
||||
// Preparo lo statement
|
||||
$stmt = $conn->prepare($sql_insert);
|
||||
if ($stmt === false) {
|
||||
echo "Errore nella preparazione della query: " . $conn->error;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Creo un array di valori e determino i tipi per il bind
|
||||
$values = array_values($row);
|
||||
$types = str_repeat("s", count($values)); // Tratto tutto come stringa per semplicità, puoi ottimizzare i tipi se necessario
|
||||
$stmt->bind_param($types, ...$values);
|
||||
|
||||
// Eseguo l'inserimento
|
||||
if ($stmt->execute()) {
|
||||
echo "Nuova riga inserita con successo in identificationparts";
|
||||
} else {
|
||||
echo "Errore nell'inserimento della nuova riga in identificationparts: " . $stmt->error;
|
||||
}
|
||||
|
||||
// Chiudo lo statement
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
// Chiudo la connessione
|
||||
$conn->close();
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user