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 クエリが正しく設定されていません ( to を指定FALSEするなどmysql_num_rows)。ほとんどの場合、WHERE句内にあります$bagianWhere。一見したところ、 と の両方$_POST['chkEmp']$_POST['chkOtdate']設定されている場合、後者は . で始まらないため、エラーが返されるように見えますAND

考えられるすべての組み合わせを使用して、クエリ自体をテストすることをお勧めします (とにかく小さいようです)。

また、デカルト積は本当にここで必要ですか?

編集:$bagianWhere .= "badge_id = '$badge_id' order and- それorderは場違いに思えますか?

于 2012-05-04T01:33:07.053 に答える