![](/img/trans.png)
[英]PHP/MySQL: Always show "No data" even though the data is exist at database table
[英]PHP_MySQL show data join table always double show
我在下面的代碼中遇到了麻煩:
<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個條件?
感謝您的幫助。
$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";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.