2016-12-13 35 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

谢谢先生,作品完美无暇 –