我的代码出现问题:
<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";
如果有两个条件,如果它有“或”&amp; “和”?
感谢您的帮助。
答案 0 :(得分: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";