메신저 : 카테고리정의되지 않은 인덱스 : 카테고리 해결할</p> <p>정의되지 않은 인덱스 내 코드에서이 오류에 geting
는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'; ?>
이 평균과 방법 Product
테이블이 categories
열이없는 것처럼 보입니다 사전
그 열이 있는지도 확실합니까? 테이블의 DB 스키마는 무엇입니까? –
btw, 스택에 아주 좋은 실적이 없습니다. –