0

我的代码有问题:
错误是:Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\siix_dev\overtime\track_reports.php on line 333

我认为连接表函数中的错误,但我无法分析这种情况的解决方案。

<?php
                    include ("config.php");

                    $bagianWhere = "";

                    if (isset($_POST['chkBadge']))
                    {
                        $badge_id = $_POST['badge_id'];
                        $status_acknowledge = "Acknowledged";
                        if (empty($bagianWhere))
                        {
                            $bagianWhere .= "badge_id = '$badge_id' order and t_submissions.submission_no=t_acknowledged.submission_no and t_acknowledged.status_acknowledge='$status_acknowledge' by time_submission DESC";
                        }
                    }

                    if (isset($_POST['chkEmp']))
                    {
                       $employee_name = $_POST['employee_name'];
                       $status_acknowledge = "Acknowledged";
                       if (empty($bagianWhere))
                        {
                            $bagianWhere .= "employee_name LIKE '$employee_name' and t_submissions.submission_no=t_acknowledged.submission_no and t_acknowledged.status_acknowledge='$status_acknowledge' order by time_submission DESC";
                        }
                        else
                        {
                            $bagianWhere .= " AND employee_name LIKE '$employee_name' and t_submissions.submission_no=t_acknowledged.submission_no and t_acknowledged.status_acknowledge='$status_acknowledge' order by time_submission DESC";
                        }
                    }

                    if (isset($_POST['chkOtdate']))
                    {
                        $date_from = $_POST['date_from'];
                        $date_to = $_POST['date_to'];
                        $status_acknowledge = "Acknowledged";

                        if (empty($bagianWhere))
                        {
                            $bagianWhere .= "ot_date between '$date_from' and '$date_to' and t_submissions.submission_no=t_acknowledged.submission_no and t_acknowledged.status_acknowledge='$status_acknowledge' order by time_submission DESC";
                        }
                        else
                        {
                            $bagianWhere .= " AND ot_date between '$date_from' and '$date_to' and t_submissions.submission_no=t_acknowledged.submission_no and t_acknowledged.status_acknowledge='$status_acknowledge' order by time_submission DESC";
                        }
                    }

                    $query = "SELECT t_submissions.submission_no, t_submissions.badge_id,
                    t_submissions.employee_name, t_submissions.ot_date, t_submissions.dept_name,
                    t_submissions.ot_from, t_submissions.ot_to,
                    t_submissions.remarks, t_submissions.submission_by, t_acknowledged.acknowledge_by,

                    FROM t_submissions, t_acknowledged WHERE ".$bagianWhere;

                    $hasil = mysql_query($query);
                                if(mysql_num_rows($hasil) > 0)
                                {
                                    ?>
                                    <div class="outer">
                                        <div id="main" class="wrapper">
                                            <div class="content-area">
                                            <table cellspacing="0" class="font">
                                                <thead>
                                                    <tr>
                                                        <th class="th">Form No</th>
                                                        <th class="th">Badge ID</th>
                                                        <th class="th">Name</th>
                                                        <th class="th">OT Date</th>
                                                        <th class="th">OT From</th>
                                                        <th class="th">OT To</th>
                                                        <th class="th">Submission By</th>
                                                        <th class="th">Status Ack.</th>
                                                        <th class="th">Status App.</th>
                                                    </tr>                                               
                                                </thead>

                                                <?php
                                                    while($submission = mysql_fetch_array($hasil))
                                                    {?>
                                                        <tbody>
                                                            <tr>
                                                                <td class="td"><?php echo $submission['submission_no'];?></td>
                                                                <td class="td"><?php echo $submission['badge_id'];?></td>
                                                                <td class="td"><?php echo $submission['employee_name'];?></td>
                                                                <td class="td"><?php echo $submission['ot_date'];?></td>
                                                                <td class="td"><?php echo $submission['ot_from'];?></td>
                                                                <td class="td"><?php echo $submission['ot_to'];?></td>
                                                                <td class="td"><?php echo $submission['submission_by'];?></td>
                                                                <td class="td"><?php echo $submission['acknowledge_by'];?></td>
                                                                <td class="td"><?php echo $submission['approval_by'];?></td>
                                                            </tr>
                                                        </tbody>
                                                    <?php 
                                                    }?>
                                            </table>
                                            </div>
                                        </div>
                                    </div>
                                    <?php
                                }
                                else
                                {
                                    echo '<p STYLE="position:absolute; TOP:170px; left:500px;">Data not found.</p>';
                                }
                    ;
                    ?>

使用日期范围输入和 2 个表关系进行搜索。

请帮我解决这个问题。谢谢你。

4

1 回答 1

0

SQL 查询设置不正确(例如提供FALSEto mysql_num_rows)。最有可能在您的WHERE条款内$bagianWhere。乍一看,如果同时设置$_POST['chkEmp']$_POST['chkOtdate'],它会返回一个错误,因为后者不以 . 开头AND

我建议您使用所有可能的组合自行测试查询(无论如何它们看起来很小)。

另外,这里真的需要笛卡尔积吗?

编辑:$bagianWhere .= "badge_id = '$badge_id' order and- 这order似乎不合适?

于 2012-05-04T01:33:07.053 回答