Skip to content

Commit

Permalink
ADDED ELABORATI JS PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
MorelliniMatteo committed Dec 22, 2023
1 parent 35019a4 commit 1be8d02
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 1 deletion.
31 changes: 31 additions & 0 deletions Elaborati/ElaboratoPHP/README_DB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Istruzioni per creare il database e la tabella

Andare in phpmyAdmin e andare nella voce di menu a tab "SQL".

1. Creare il DB

CREATE DATABASE giugno

2. Andare nel database appena creato e create la tabella

CREATE TABLE `insiemi` (
`id` int(11) NOT NULL,
`valore` int(11) NOT NULL,
`insieme` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf16;

ALTER TABLE `insiemi`
ADD PRIMARY KEY (`id`);

ALTER TABLE `insiemi`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

3. Popolare il DB

INSERT INTO `insiemi` (`id`, `valore`, `insieme`) VALUES
(1, 19, 1),
(2, 2, 1),
(3, 14, 1),
(4, 98, 2),
(5, 1, 2),
(6, 19, 2);
72 changes: 72 additions & 0 deletions Elaborati/ElaboratoPHP/matteo.morellini.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "giugno";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connessione fallita: " . $conn->connect_error);
}

function isNumeroPresente($numero, $conn)
{
$query = "SELECT COUNT(*) as count FROM insiemi WHERE valore = $numero";
$result = $conn->query($query);
$row = $result->fetch_assoc();
return $row['count'] > 0;
}

$A = $_GET['A'] ?? null;
$B = $_GET['B'] ?? null;
$O = $_GET['O'] ?? null;

if (!is_numeric($A) || !is_numeric($B) || $A <= 0 || $B <= 0 || !isNumeroPresente($A, $conn) || !isNumeroPresente($B, $conn) || ($O !== 'i' && $O !== 'u')) {
echo "Parametri non validi o non presenti nel database o operazione non supportata.";
} else {
$queryA = "SELECT valore FROM insiemi WHERE insieme = $A";
$resultA = $conn->query($queryA);
$insiemeA = [];
while ($rowA = $resultA->fetch_assoc()) {
$insiemeA[] = $rowA['valore'];
}

$queryB = "SELECT valore FROM insiemi WHERE insieme = $B";
$resultB = $conn->query($queryB);
$insiemeB = [];
while ($rowB = $resultB->fetch_assoc()) {
$insiemeB[] = $rowB['valore'];
}

if ($O === 'u') {
$nuovoInsieme = array_unique(array_merge($insiemeA, $insiemeB));
} elseif ($O === 'i') {
$nuovoInsieme = array_intersect($insiemeA, $insiemeB);
}

if (!empty($nuovoInsieme)) {
// Trova il massimo ID attualmente presente nel database e aggiungi 1 per ottenere il nuovo ID
$maxIdQuery = "SELECT MAX(insieme) AS max_insieme FROM insiemi";
$resultMaxId = $conn->query($maxIdQuery);
$rowMaxId = $resultMaxId->fetch_assoc();
$newId = $rowMaxId['max_insieme'] + 1;

$insertQuery = "INSERT INTO insiemi (valore, insieme) VALUES ";
foreach ($nuovoInsieme as $valore) {
$insertQuery .= "($valore, $newId),";
}
$insertQuery = rtrim($insertQuery, ',');

if ($conn->query($insertQuery) === TRUE) {
echo "Operazione completata con successo!";
} else {
echo "Errore nell'inserimento dei dati: " . $conn->error;
}
} else {
echo "Nessun dato da inserire.";
}
}

$conn->close();
?>
Binary file added Elaborati/ElboratoJS/css.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Elaborati/ElboratoJS/dimostrazione.mkv
Binary file not shown.
Binary file added Elaborati/ElboratoJS/html.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Elaborati/ElboratoJS/jquery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions Elaborati/ElboratoJS/matteo.morellini.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Mio sito</title>
<style>
div.slider-image{
margin-top: 20px;
text-align: center;
}
div.slider-image img{
display: inline-block;
width: 100px;
}
div.slider-image img.current{
width: 200px;
}
</style>
</head>
<body>
<header>
<h1>Esercizio javascript/jQuery</h1>
</header>
<main>
<h2>Tecnologie</h2>
<div class="slider">
<div class="slider-image">
<img src="html.png" alt="Html" />
<img src="css.png" alt="Css" />
<img src="jquery.png" alt="jQuery" />
<img src="php.png" alt="Php" />

</div>
</div>
</main>
</body>
<script src="matteo.morellini.js" type="text/javascript"></script>

</html>
36 changes: 36 additions & 0 deletions Elaborati/ElboratoJS/matteo.morellini.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
document.addEventListener("DOMContentLoaded", function() {
const images = document.querySelectorAll('.slider-image img');
const totalImages = images.length;

for (let i = 2; i < totalImages; i++) {
images[i].style.display = 'none';
}

images[0].classList.add('current');
images[1].style.display = 'inline-block';

images.forEach(function(image, index) {
image.addEventListener('click', function() {
if (!this.classList.contains('current')) {
const currentIndex = Array.from(images).indexOf(this);

images.forEach(function(img) {
img.classList.remove('current');
img.style.display = 'none';
});

this.classList.add('current');
this.style.display = 'inline-block';

if (currentIndex === 0) {
images[1].style.display = 'inline-block';
} else if (currentIndex === totalImages - 1) {
images[currentIndex - 1].style.display = 'inline-block';
} else {
images[currentIndex - 1].style.display = 'inline-block';
images[currentIndex + 1].style.display = 'inline-block';
}
}
});
});
});
Binary file added Elaborati/ElboratoJS/php.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion things/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ button:hover{
transform: translateY(-180px);
transition: .8s ease-in-out;
}
.login label{
.login label{
color: #573b8a;
transform: scale(.6);
}
Expand Down

0 comments on commit 1be8d02

Please sign in to comment.