2016-04-23 85 views
0

我有2個數據表:
表1第二個數據表不顯示 「無可用數據」 消息

<table id="properties_list" class="table"> 
    <thead> 
    <tr class="backend_tab_header"> 
     <th>Status</th> 
     <th>Photo</th> 
     <th>Property ID</th> 
     <th>Address</th> 
     <th>Date Created</th> 
     <th>Owner</th> 
    </tr> 
    </thead> 
    <tbody> 
    <?php 
    foreach ($properties as $property) 
    { 
     ?> 
     <tr> 
      <td><?php print $property["status"]; ?></td> 
      <td class="pic_prop_table"><img class="img-responsive" src="<?php print $property["url"]; ?>" ></td> 
      <td><?php print $property["prop_id"]; ?></td> 
      <td><?php print $property["address"]; ?></td> 
      <td><?php print $property["date_created"]; ?></td> 
      <td><?php print $property["first_name"]; ?>&nbsp;<?php print $property["last_name"]; ?></td> 
     </tr> 
     <?php 
    } 

    ?> 
    </tbody> 
</table> 

表2

<table id="messages_list" class="table"> 
       <thead> 
        <tr class="backend_tab_header"> 
         <th>Property ID</th> 
         <th>Subject</th> 
         <th>Message</th> 
         <th>Received</th> 
        </tr> 
       </thead> 
       <tbody> 
       <?php 
        foreach ($properties as $property) 
        { 
         ?> 
         <tr> 
          <td><?php print $messages["from_user"]; ?></td> 
          <td><?php print $messages["subject"]; ?></td> 
          <td><?php print $messages["message"]; ?></td> 
          <td><?php print $messages["date_sent"]; ?></td> 
         </tr> 
         <?php 
        } 
       ?> 
       </tbody> 
      </table> 

,並填補了陣列叫我的PHP功能在頁面頂部:

$properties = $auth_user->getPropertiesByUser($_SESSION['user_session']); 
$messages = $auth_user->getMessages($_SESSION['user_session']); 

數據表是用JS

jQuery(document).ready(function() { 
jQuery('table#properties_list').DataTable({ 
    //ajax:   '../ajax/data/arrays.txt', 
    scrollY:  200, 
    scrollCollapse: true, 
    paging:   false 
}); 
jQuery('table#messages_list').DataTable({ 
    //ajax:   '../ajax/data/arrays.txt', 
    scrollY:  200, 
    scrollCollapse: true, 
    paging:   false 
}); 

});

我的問題是,當第一個數組($屬性)返回空的第一個表顯示消息「表中沒有數據可用」,當兩個數組($ properties和$ messages)返回空時,兩個表都顯示消息「表中沒有可用數據」,但是當$ properties數組返回info和$ messages數組返回空時,第二個表(消息)不會顯示「表中沒有可用數據」,並且還會創建儘可能多的<td>元素作爲<td>元素在第一張表(屬性)。誰能告訴我這是什麼原因? 在此先感謝

+0

第二個調用看起來像引用$ properties而不是$ messages – Damon

回答

0

可能是因爲兩個pop中的每個使用$屬性。在第二個循環中,它獲取第一個的$屬性。

嘗試在獲取值或使用其他變量名稱之前設置$ properties = array()。

相關問題