0

我的代码有问题:

<form name="form" method="get" action="" autocomplete="off">
                                    <input class="text sign" type="text" name="q" id="q" onkeyup="SetButtonStatus(this, 'btnButton')"/>
                                    <span class="hint"><b>Tips :</b>
                                        <br>
                                        1. Search by <b>badgeid</b>, ex : 110702.<br>
                                        2. Search by <b>name</b>, ex : david.<br>
                                        3. Search by <b>otdate</b>, ex : 9-feb-2012.
                                    </span>
                                    <br>
                                    <input class="submit" type="submit" value="Search" ID="btnButton" disabled="disabled"/>
                                </form>

                            <?php
                                if(isset($_GET['q']) && $_GET['q'])
                                {
                                    include ("config.php");
                                    $q = $_GET['q'];
                                    $sql = "select t_submissions.submission_no,
                                    t_submissions.badge_id,
                                    t_submissions.employee_name,
                                    t_submissions.ot_date,
                                    t_submissions.ot_from,
                                    t_submissions.ot_to,
                                    t_submissions.submission_by,
                                    t_acknowledged.status_acknowledge,
                                    t_submissions.status_approve

                                    from t_submissions, t_acknowledged where t_submissions.employee_name like '%$q%' or ot_date like '%$q%' or t_submissions.badge_id like '%$q%' or t_submissions.submission_no=t_acknowledged.submission_no ORDER BY time_submission DESC";

                                    $result = mysql_query($sql) or trigger_error(mysql_error().$sql);
                                    if(mysql_num_rows($result) > 0)
                                    {
                                        ?>
                                        <div class="outer">
                                            <div style="height:342px; overflow:auto; width:818px;">
                                                <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($result))
                                                        {?>
                                                        <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['status_acknowledge'];?></td>
                                                                <td class="td"><?php echo $submission['status_approve'];?></td>
                                                            </tr>
                                                        </tbody>
                                                    <?php }?>
                                                </table>
                                            </div>
                                        </div>
                                        <?php
                                    }
                                    else
                                    {
                                        echo '<p STYLE="position:absolute; TOP:170px; left:500px;">Data not found.</p>';
                                    }
                                }
                            ?>

这段代码没有错误,但还没有用。因为当我尝试查找(例如:按日期查找:“2012 年 4 月 27 日”)时,数据显示,但它显示双数据,而在数据库中不是双数据。

我怀疑这里的代码可能是:

$sql = "select t_submissions.submission_no,
                                    t_submissions.badge_id,
                                    t_submissions.employee_name,
                                    t_submissions.ot_date,
                                    t_submissions.ot_from,
                                    t_submissions.ot_to,
                                    t_submissions.submission_by,
                                    t_acknowledged.status_acknowledge,
                                    t_submissions.status_approve

                                    from t_submissions, t_acknowledged where t_submissions.employee_name like '%$q%' or ot_date like '%$q%' or t_submissions.badge_id like '%$q%' and t_submissions.submission_no=t_acknowledged.submission_no ORDER BY time_submission DESC";

如果它有“或”和“和”,如何结合2个条件?

谢谢你的帮忙。

4

1 回答 1

0
$sql = "select t_submissions.submission_no,
                                t_submissions.badge_id,
                                t_submissions.employee_name,
                                t_submissions.ot_date,
                                t_submissions.ot_from,
                                t_submissions.ot_to,
                                t_submissions.submission_by,
                                t_acknowledged.status_acknowledge,
                                t_submissions.status_approve
                                from t_submissions, t_acknowledged where      
(t_submissions.employee_name like '%$q%' 
or ot_date like '%$q%' 
or t_submissions.badge_id like '%$q%') 
and t_submissions.submission_no=t_acknowledged.submission_no 
ORDER BY time_submission DESC";
于 2012-04-27T03:05:56.110 回答