duanneng2014 2013-04-13 13:28
浏览 35
已采纳

如何显示不匹配的mysql结果

i m trying to create school fees recipt system

i create two table in phpmyadmin 1 is admission and 2nd is fees

1.admission i create admission php form when i fill the admission form all detail save in admission table

2.fees the same thing i create it in fees page

in admission table have all student info who are study in our school

and in fees table all info of student who paid the fees of the month

but now i want student fees report who are paid and who are not paid the fees

this code showing only paid student report

but i want both result who are paid and who are not paid how can i do this

please help me to fix this issue

<?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);
?>
  • 写回答

2条回答 默认 最新

  • dqg95034 2013-04-13 13:39
    关注

    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
    ", 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); 
    ?>      
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 如果update 一个列名为参数的value
  • ¥15 基于51单片机的水位检测系统设计中LCD1602一直不显示
  • ¥15 OCS2安装出现问题,请大家给点意见
  • ¥15 ros小车启动launch文件报错
  • ¥15 vs2015到期想登陆但是登陆不上
  • ¥15 IPQ5018制作烧录固件,boot运行失败(操作系统-linux)(相关搜索:操作系统)(相关搜索:操作系统)
  • ¥20 icefall在librispeech基础上加入个人数据集
  • ¥30 keepalive高可用故障运维配置询问
  • ¥15 求帮助!国家电网内网u盘突然识别不出来了。
  • ¥15 matlab语音变速变调同时实现