while循环if语句

时间:2014-03-06 04:43:27

标签: php

我有下面的代码,哪些工作宣布只加载一个我在循环中使用的记录,但是没有工作。

<?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\">&nbsp;
<tr>
    <th><p class=\"slide-title\"><strong>Title &nbsp;&nbsp;</strong></p></th>
    <th><p class=\"slide-title\"><strong>Location &nbsp;&nbsp;</p></strong></th>
    <th><p class=\"slide-title\"><strong>Expiry Date &nbsp;&nbsp;</p></strong></th>
</tr>";
while($result1=mysql_fetch_array($query)){
    echo "<tr>
    <td>";echo $result1['job_title']; echo "</td>&nbsp;&nbsp;
    <td>";echo $result1['job_location']; echo "</td>&nbsp;&nbsp;
    <td>";echo $result1['job_exp_date']; echo "</td>
</tr>"; } echo " 
</table>"; 
 }
?>

4 个答案:

答案 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\">&nbsp;
        <tr>
            <th><p class=\"slide-title\"><strong>Title &nbsp;&nbsp;</strong></p></th>
            <th><p class=\"slide-title\"><strong>Location &nbsp;&nbsp;</p></strong></th>
            <th><p class=\"slide-title\"><strong>Expiry Date &nbsp;&nbsp;</p></strong></th>
        </tr>";
        while($result1=mysql_fetch_array($query))
        {
            echo "<tr>
                <td>";echo $result1['job_title']; echo "</td>&nbsp;&nbsp;
                <td>";echo $result1['job_location']; echo "</td>&nbsp;&nbsp;
                <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\">&nbsp;
<tr>
    <th><p class=\"slide-title\"><strong>Title &nbsp;&nbsp;</strong></p></th>
    <th><p class=\"slide-title\"><strong>Location &nbsp;&nbsp;</p></strong></th>
    <th><p class=\"slide-title\"><strong>Expiry Date &nbsp;&nbsp;</p></strong></th>
</tr>";
while($result=mysql_fetch_array($query)){
    echo "<tr>
    <td>";echo $result['job_title']; echo "</td>&nbsp;&nbsp;
    <td>";echo $result['job_location']; echo "</td>&nbsp;&nbsp;
    <td>";echo $result['job_exp_date']; echo "</td>
</tr>"; } echo " 
</table>"; 
 }
?>

尝试这个......当你想检查查询得到结果或不使用“mysql_num_rows”

答案 3 :(得分:0)

Try this code... it's helpful to you  :-)

代码中的小错误。我改变了你的代码,但是工作正常......