2016-12-13 40 views
-1

IM在我的代碼歌廳此錯誤未定義指數:類解決

未定義指數:類

Notice: Undefined index: categories in C:\xampp\htdocs\project\admin\products.php on line 14 

這是行14

$child_id = $product['categories']; 

,這是整個代碼

<?php 
require_once $_SERVER['DOCUMENT_ROOT'].'/project/core/init.php'; 
include 'includes/head.php'; 
include 'includes/navigation.php'; 
$sql = "SELECT * FROM Products WHERE deleted = 0"; 
$presults = $db->query($sql); 
?> 
<h2 class="text-centre" style="text-align: center;">Products</h2><hr> 
<table class="table table-boedered table-condensed table-striped"> 
<thead><th></th><th>Products</th><th>Price</th><th>Category</th><th>Featured</th><th>Sold</th></thead> 
<tbody> 
    <?php while($product = mysqli_fetch_assoc($presults)): 
      // Trying to display the parent category for every product 
       $child_id = $product['categories']; 
       $catSql = "SELECT * FROM categories WHERE id = '$child_id'"; 
       $result = mysqli_query($db, $catSql); 
       $child = mysqli_fetch_assoc($result); 
       $parentID = $child['parent_id']; 
       $pSql = "SELECT * FROM categories WHERE id = '$parentID'"; 
       $presult = mysqli_query($db, $pSql); 
       $parent = mysqli_fetch_assoc($presult); 
       $category = $parent['category'] . '-' . $child['category']; 
       // Idea for future. Will have nested categories. Only display immediate parent category of product 
      ?> 
    <tr> 
     <td> 
      <a href="Products.php?edit=<?=$Product['id'];?>" class="btn btn-xs btn-defualt"><span class="glyphicon glyphicon-pencil"></span></a> 
      <a href="Products.php?delete=<?=$Product['id'];?>" class="btn btn-xs btn-defualt"><span class="glyphicon glyphicon-remove"></span></a> 
     </td> 
     <td><?=$product['title']; ?></td> 
     <td><?=money($product['price']);?></td> 
     <td><?=$category; ?></td> 
     <td>o</td> 
    </tr> 
    <?php endwhile; ?> 
</tbody> 
</table> 



<?php include 'includes/footer.php'; ?> 

這是什麼意思,如何解決它

在此先感謝

+0

你確定該列甚至存在?表格的數據庫模式是什麼? –

+0

順便說一句,你沒有一個很好的記錄在這裏堆棧 –

回答

0

這似乎表明您Product表沒有一個categories列。 加入此驗證,行14日前:

var_dump($product); 

然後您將看到$product陣列可以一起工作,你可以驗證,你應該從類別ID。

+0

Bonne chance de voir le p'tit check en vert ;-)該OP沒有一個很好的記錄; dommage。呃斌... quoi faire(?)。 –

+0

謝謝先生,作品完美無暇 –