doufanglian7585 2012-04-27 01:46
浏览 16
已采纳

PHP_MySQL显示数据连接表总是双显示

I have a trouble with my code below :

<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>';
                                    }
                                }
                            ?>

This code are not error but not yet useful. because when I try to find (example : find by date : "27-Apr-2012") the data show, but it show with double data whereas in database that's not a double data.

I suspect the code in here maybe :

$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";

how to combine 2 condition if it has "or" & "and" ?

Thank you for helping.

  • 写回答

1条回答 默认 最新

  • doulu4233 2012-04-27 03:05
    关注
    $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";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退