2013-04-21 124 views
2

我是相對較新的PHP,我面臨一個問題,而我從我的數據庫表中檢索數據...表的名稱是'離開'。更重要的是,我不得不說我可以很容易地從同一個數據庫的另一個表中檢索數據。我使用的是開源數據庫,'leave'表是由me.is創建的,原因是 - 其實我找不到任何此問題的原因。使用和mysql_fetch_row(),但我有一個錯誤遵循從表中檢索數據

警告:mysql_fetch_row()能夠預計參數1是資源,布爾 在C中給出:\ XAMPP \ htdocs中\ attendance_system \上線42

admin_leave.php

您的SQL語法有錯誤;檢查 對應於你的MySQL服務器版本使用 附近的假'在行1

這裏是我的代碼正確的語法手冊......請幫我在這裏

代碼

<?php 
/*@session_start(); 
if (isset($_SESSION['username']) && $_SESSION['username']) { 

} else { 

header("Location: index.php"); 
} 
$title = 'Leave Application';*/ 
include_once 'config.php'; 
include('header.php'); 
?> 
<div class="grid_12"> 
<div class="contentpanel"> 

    <h2 align="center">Leave Application</h2> 

    <?php 

     $sql = mysql_query('select * from leave'); 

    ?> 
    <table class="list" cellspacing="0" cellpadding="5" border="1"> 
     <thead> 
      <tr> 
       <th>&nbsp;</th> 
       <th>Employee ID</th> 
       <th>Employee Name</th> 
       <th>User Name</th> 
       <th>Leave Days</th> 
       <th>Start Date</th> 
       <th>End Date</th> 
       <th>Reason</th> 


      </tr> 
     </thead> 

     <tbody> 

     <?php 
      while($w= mysql_fetch_row($sql) or die(mysql_error())) 
      { 
       echo 
       "<tr> 
       <td>&nbsp;</td> 
       <td>".$w[0]."</td> 
       <td>".$w[1]."</td> 
       <td>".$w[2]."</td> 
       <td>".$w[3]."</td> 
       <td>".$w[4]."</td> 
       <td>".$w[5]."</td> 
       <td>".$w[6]."</td> 





       </tr>"; 

      } 
     ?> 


     </tbody> 


    </table> 
    <br/> 
    <br/> 
</div> 
</div> 
<?php include('footer.php'); ?> 

回答

1

Leave在MySQL中

關鍵字,您需要把表名反引號。

使用此:

$sql = mysql_query('select * from `leave`'); 
+0

MySQL使用反引號,括號不,引用保留字。 – Barmar 2013-04-21 03:22:10

+0

@Barmar:謝謝你的糾正.. – 2013-04-21 03:23:39

+0

mr.San ...謝謝。它現在工作.. – Tanvir 2013-04-21 03:45:32