2014-03-06 153 views
0

我有波紋管代碼哪些工作宣佈哪些只加載一條記錄我用循環哪些不起作用。當過要CHEC雖然循環在if語句

<?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>"; 
} 
?> 
+0

http://stackoverflow.com/questions/2974011/while-row-mysql-fetch-arrayresult-how-many-loops-are-正在執行 – ray

+0

是不是「while($ result1 = mysql_fetch_array($ result))」 – ray

回答

0

嘗試改變

$result=mysql_fetch_assoc($query); 

$result=mysql_num_rows($query); 
+0

謝謝你的幫助。 – user3314254

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

試試這個...... K表查詢得到的結果或不使用「mysql_num_rows」

0

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

只是輕微的錯誤在你的代碼。我改變了你的代碼只是一點點的變化,它的工作正常...