我有下面的代码,哪些工作宣布只加载一个我在循环中使用的记录,但是没有工作。
<?php
$job="SELECT * from jobs where job_exp_date>=now()";
$query=mysql_query($job);
$result=mysql_fetch_assoc($query);
if($result==0) {
echo "Sorry We Don't have current openings. Thank you for your intreset";
}else{
echo"<table width=\"auto\">
<tr>
<th><p class=\"slide-title\"><strong>Title </strong></p></th>
<th><p class=\"slide-title\"><strong>Location </p></strong></th>
<th><p class=\"slide-title\"><strong>Expiry Date </p></strong></th>
</tr>";
while($result1=mysql_fetch_array($query)){
echo "<tr>
<td>";echo $result1['job_title']; echo "</td>
<td>";echo $result1['job_location']; echo "</td>
<td>";echo $result1['job_exp_date']; echo "</td>
</tr>"; } echo "
</table>";
}
?>
答案 0 :(得分:0)
尝试更改
$result=mysql_fetch_assoc($query);
到
$result=mysql_num_rows($query);
答案 1 :(得分:0)
使用此
<?php
$job="SELECT * from jobs where job_exp_date>=now()";
$query=mysql_query($job);
if(mysql_num_rows($query) == 0)
{
echo "Sorry We Don't have current openings. Thank you for your intreset";
}
else
{
echo "<table width=\"auto\">
<tr>
<th><p class=\"slide-title\"><strong>Title </strong></p></th>
<th><p class=\"slide-title\"><strong>Location </p></strong></th>
<th><p class=\"slide-title\"><strong>Expiry Date </p></strong></th>
</tr>";
while($result1=mysql_fetch_array($query))
{
echo "<tr>
<td>";echo $result1['job_title']; echo "</td>
<td>";echo $result1['job_location']; echo "</td>
<td>";echo $result1['job_exp_date']; echo "</td>
</tr>";
}
echo "</table>";
}
?>
答案 2 :(得分:0)
<?php
$job="SELECT * from jobs where job_exp_date>=now()";
$query=mysql_query($job);
$rows=mysql_num_rows($query);
if($rows==0) {
echo "Sorry We Don't have current openings. Thank you for your intreset";
}else{
echo"<table width=\"auto\">
<tr>
<th><p class=\"slide-title\"><strong>Title </strong></p></th>
<th><p class=\"slide-title\"><strong>Location </p></strong></th>
<th><p class=\"slide-title\"><strong>Expiry Date </p></strong></th>
</tr>";
while($result=mysql_fetch_array($query)){
echo "<tr>
<td>";echo $result['job_title']; echo "</td>
<td>";echo $result['job_location']; echo "</td>
<td>";echo $result['job_exp_date']; echo "</td>
</tr>"; } echo "
</table>";
}
?>
尝试这个......当你想检查查询得到结果或不使用“mysql_num_rows”
答案 3 :(得分:0)
代码中的小错误。我改变了你的代码,但是工作正常......