I have a database with three tables "Cantiere "Affidataria "SubAffidataria" "Cantiere" has a 1 to N relationship with Affidataria "Affidataria" has a 1 to N relationship with subAffidataria so in Affidataria there is a fk of "Cantiere" called "fkIdCantiere" and in subAffidataria there is a fk of "Affidataria" called "fkIDAffidataria" my problem is to go from a "function" to the id of fkIdAffidataria in fact, if you notice in the screenshot you see the carers but not the sub-delegates. so I have to make sure to save the fkIdAffidataria to put it in the QUERY ..
"0 results" indicates that the query did not find any subAffidataria .. when in fact they are in the database
<!DOCTYPE html>
<?php
session_start();
if(!isset($_SESSION["username"]))
{
header('location: ../index.php');
}
else
{
?>
<?php
$servername = "localhost";
$username = "progettocantiere";
$password = "";
$dbname = "my_progettocantiere";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$idCantiere = $_GET['idCantiere'];
$sql1 = "SELECT idAffidataria,nomeCantiere,fkIDCantiere
FROM Affidataria
WHERE fkIDCantiere = '$idCantiere'";
echo($idAffidataria);
$idAffidataria = $_GET['idAffidataria'];
$result1 = $conn->query($sql1);
if ($result1->num_rows > 0) {
// output data of each row
while($row = $result1->fetch_assoc()) {
echo'<br><br><br>';
echo '<h3>Affidataria</h3>';
echo '<a class="myButton" href="../../pagineHtml/visualizza/visualizzazione/affidatario.php?idAffidataria=' . $row["idAffidataria"] . '">' . $row["nomeCantiere"] . '</a>';
echo '<a class="myButton" href="../../pagineHtml/visualizza/visualizzazione/affidatario.php?idAffidataria=' . $row["idAffidataria"] . '">Stampa PDF ' . $row["nomeCantiere"] . '</a>';
echo '<a class="myButton" href="../../pagineHtml/visualizza/visualizzazione/affidatario.php?idAffidataria=' . $row["idAffidataria"] . '">Esporta Directory Interna ' . $row["nomeCantiere"] . '</a>';
echo '<a class="myButton" href="../../pagineHtml/visualizza/visualizzazione/affidatario.php?idAffidataria=' . $row["idAffidataria"] . '">Stampa Personale ' . $row["nomeCantiere"] . '</a>';
echo '<a class="myButton" href="../../pagineHtml/visualizza/visualizzazione/affidatario.php?idAffidataria=' . $row["idAffidataria"] . '">Esporta Directory Personale ' . $row["nomeCantiere"] . '</a>';
echo '<a class="myButton" href="../../pagineHtml/visualizza/visualizzazione/affidatario.php?idAffidataria=' . $row["idAffidataria"] . '">Stampa Mezzi ' . $row["nomeCantiere"] . '</a>';
echo '<a class="myButton" href="../../pagineHtml/visualizza/visualizzazione/affidatario.php?idAffidataria=' . $row["idAffidataria"] . '">Esporta Directory Mezzi ' . $row["nomeCantiere"] . '</a>';
}
echo'<br><br><br>';
} else {
echo "0 results";
}
$conn->close();
?>
//subAffidatario
<?php
$servername = "localhost";
$username = "progettocantiere";
$password = "";
$dbname = "my_progettocantiere";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql1 = "SELECT * FROM SubAffidatario
WHERE fkIdAffidataria = '$idAffidataria'";
echo($idSubAffidatario);
$result1 = $conn->query($sql1);
if ($result1->num_rows > 0) {
// output data of each row
while($row = $result1->fetch_assoc()) {
echo'<br><br><br>';
echo '<a class="myButton" href="../../pagineHtml/visualizza/visualizzazione/subAffidatario.php?idSubAffidatario=' . $row["idSubAffidatario"] . '">' . $row["ragioneSocialeSubAffidatario"] . '</a>';
}
echo'<br><br><br>';
echo '<a href="../../pagineHtml/inserimento/inserimentoGenerale/inserimentoCantiere.php" class="myButton" alt="Nuovo Cantiere +">Nuovo Cantiere +</a>';
} else {
echo "0 results";
}
$conn->close();
?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Progetto Cantiere</title>
<!-- Bootstrap -->
<link href="../paginaIniziale/css/bootstrap-4.0.0.css" rel="stylesheet">
</head>
<body>
</body>
</html>
<?php } ?>
</div>