0

我正在尝试创建学费收据系统

我在 phpmyadmin 中创建了两个表 1 是入场,2 是费用

1.admission 我在填写录取表格时创建录取 php 表格,所有详细信息都保存在录取表格中

2.fees 与我在费用页面中创建的相同

在录取表中有在我们学校学习的所有学生信息

并在费用表中支付了当月费用的学生的所有信息

但现在我想要学生费用报告谁支付了谁没有支付费用

此代码仅显示付费学生报告

但我想要结果谁有薪和谁没有薪我该怎么做

请帮我解决这个问题

<?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("student", $con);

    echo "<div id='non-printable'><table class='sortable' border='1' cellpadding='10'>";
    echo "<tr> <th>No</th> <th>Name</th><th>Date</th><th>GRN</th> <th>Reference</th><th>Class</th><th>Roll No</th><th>Fees</th></tr>";

    // get results1 from database
    $result1 = mysql_query("SELECT fees.id,fees.name,fees.date,fees.grn,fees.reference,fees.class,fees.rollno,fees.fees, admission.mothername "." FROM fees, admission ". " WHERE fees.name = admission.name AND fees.date BETWEEN '2013-04-01' AND '2013-04-14' AND fees.class='6' order by class ASC");
    while($row = mysql_fetch_array($result1))
    {
        // echo out the contents of each row into a table
        echo "<tr>";
        echo '<td>' . $row['id'] . '</td>';
        echo '<td>' . $row['name'] . '</td>';
        echo '<td>' . $row['date'] . '</td>';
        echo '<td>' . $row['grn'] . '</td>';
        echo '<td>' . $row['reference'] . '</td>';
        echo '<td>' . $row['class'] . '</td>';
        echo '<td>' . $row['rollno'] . '</td>';
        echo '<td>' . $row['fees'] . '</td>';
        echo '<td>' . $row['mothername'] . '</td>';
        echo "</tr>"; 

        //Increment the value of the Total_total variable
        //by the salary value of one row till the while loop finishes
        $Total_fees=$Total_fees+$row['fees'];
    }

    echo "<tr>";
    echo '<td>Total</td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '<td>' . $Total_fees .'</td>';
    echo "</tr>";  

    // close table>
    echo "</table>";


    mysql_close($con);
?>
4

2 回答 2

0
$result1 = mysql_query("SELECT fees.id, fees.name, fees.date, fees.grn, 
   fees.reference, fees.class, fees.rollno, fees.fees, admission.mothername ".
      "FROM admission LEFT JOIN fees ON fees.name = admission.name". 
    "WHERE fees.date BETWEEN '2013-04-01' AND '2013-04-14' AND fees.class='6' 
    order by class ASC");

使用左连接,您可以获得准入表的所有行和费用表的相应行。这样您也可以获得费用表的空白数据。

于 2013-04-13T13:36:44.583 回答
0

UPDATED

<?php
    echo "<div id='non-printable'><table class='sortable' border='1' cellpadding='10'>";
    echo "<tr> <th>No</th> <th>Name</th><th>Date</th><th>GRN</th> <th>Reference</th><th>Class</th><th>Roll No</th><th>Fees</th></tr>";

    $dbserver = 'localhost'; 
    $dblogin  = 'root';
    $dbpassword = '';  
    $dbname = 'student';

    //opening connection
    $mysqli = new mysqli($dbserver, $dblogin, $dbpassword, $dbname);
    if (mysqli_connect_errno()) 
    {
        printf("Connection failed: %s\n", mysqli_connect_error());
        exit();
    }

    //opening connection
    $result = $mysqli->query("SELECT `name`, `mothername` FROM `admission` WHERE `class` = '6' ORDER BY `name` ASC") or die($mysqli->error.__LINE__);
    while($student = $result->fetch_assoc())
    {
        $subresult = $mysqli->query("SELECT * FROM `fees` WHERE `name` = '".$student['name']."' AND `date` BETWEEN '2013-04-01' AND '2013-04-14'") or die($mysqli->error.__LINE__);
        if($row = $subresult->fetch_assoc())
        {
            echo "<tr>";
            echo '<td>Student</td>';
            echo '<td>' . $row['id'] . '</td>';
            echo '<td>' . $row['name'] . '</td>';
            echo '<td>' . $row['date'] . '</td>';
            echo '<td>' . $row['grn'] . '</td>';
            echo '<td>' . $row['reference'] . '</td>';
            echo '<td>' . $row['class'] . '</td>';
            echo '<td>' . $row['rollno'] . '</td>';
            echo '<td>' . $row['fees'] . '</td>';
            echo '<td>' . $student['mothername'] . '</td>';
            echo "</tr>"; 

        }
        else
        {
            echo "<tr>";
            echo '<td>' . $student['name'] . '</td>';
            echo '<td> didn\'t pay any fee.</td>';
            echo "</tr>";
        }
    }
            echo '</table>';

mysqli_close($mysqli); 
?>      
于 2013-04-13T13:39:45.920 回答