doulan3966 2018-10-17 07:38
浏览 63

使用mySql DB创建PHP按钮

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 ..

enter image description here

"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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。