【发布时间】:2015-11-05 19:28:21
【问题描述】:
我在 mysql 中有 2 个表;
itemscategories
items 有一个 cat_id 列指向 categories 表中的类别
我使用以下查询来获取项目和类别;
SELECT a.id, a.cat_id, a.rest_id, a.name, a.description, a.price, b.rest_id, b.name
FROM items a, categories b
WHERE a.cat_id = b.id AND b.rest_id = 1
我想使用 ng-repeat 生成如下列表;
Category A
Item (belongs to cat A)
Item (belongs to cat A)
Item (belongs to cat A)
Category B
Item (belongs to cat B)
Item (belongs to cat B)
Item (belongs to cat B)
我如何使用ng-repeat 实现这一目标
到目前为止我有这个,但没有工作;
<div class="results-group" ng-repeat="(key, value) in fetchedData">
<h3 style="text-align: left;"></h3>
<ul>
<li ng-repeat="data in value">
</li>
<ul>
</div>
谢谢。
$query1 = "SELECT * FROM categories WHERE rest_id = $restaurant_id";
$select_all_cats = mysqli_query($connection, $query1);
$rows = $select_all_cats -> num_rows;
$arr1 = array();
$arr2 = array();
if($rows > 0) {
while($rows = mysqli_fetch_assoc($select_all_cats)) {
$arr1[] = $rows;
$cat_id = $rows['id'];
$query2 = "SELECT * FROM items WHERE cat_id = $cat_id";
$select_all_items = mysqli_query($connection, $query2);
$rowx = $select_all_items -> num_rows;
if($rowx > 0) {
while($rowx = mysqli_fetch_assoc($select_all_items)) {
$arr2[] = $rowx;
}
}
}
}
【问题讨论】:
-
您可以使用 2 个查询来处理此问题,一个用于循环查找类别,另一个用于查找项目
-
我如何实现我想要的列表?
标签: php mysql angularjs angularjs-ng-repeat ng-repeat