Php 输出中缺少行
我有一个小问题,我找不到答案 我有一个名为Php 输出中缺少行,php,mysql,select,Php,Mysql,Select,我有一个小问题,我找不到答案 我有一个名为product\u features的表,其中包含以下字段: product_features ---------------------- id parent_id name order added_date 现在的问题是,我刚刚插入了两行名称相同的行: 734 1 6008-2 test 0 2012-11-21 11:52:28 735 1 6008-2 test 0 2012
product\u features
的表,其中包含以下字段:
product_features
----------------------
id parent_id name order added_date
现在的问题是,我刚刚插入了两行名称相同的行:
734 1 6008-2 test 0 2012-11-21 11:52:28
735 1 6008-2 test 0 2012-11-21 11:57:27
我已经定义了id-主索引-自动递增
和parent\u id-索引
Keyname Type Unique Packed Column Cardinality Collation
PRIMARY BTREE Yes No product_feature_id 671 A
product_feature_parent_id BTREE No No product_feature_parent_id 671 A
当我打印结果时,只打印最后一行。。我真的不明白为什么。这是我正在使用的函数:
public function printProductFeaturesTable($product_feature_parent_id = 0, $level = 0){
$sql = $this->mysqli->query("SELECT product_feature_id, product_feature_name
FROM product_features
WHERE product_feature_parent_id='" . $product_feature_parent_id . "'
ORDER BY product_feature_order");
if($sql->num_rows != 0) {
if($level != 0)
echo '<table cellpadding="0" cellspacing="1" class="dnd"><tbody>';
$i = 0;
while($row = $sql->fetch_assoc()) {
$i++;
echo '<tr>
<td width="30" valign="top" align="center">',
$i, '.
</td>
<td>',
$row['product_feature_name'],
'<div class="table-options">
<input type="hidden" name="product_feature_id[]" value="', $row['product_feature_id'], '" />
<a href="/admin/product-features/add-modify/', $row['product_feature_id'], '" class="ui-state-default ui-corner-all left"><span class="ui-icon ui-icon-pencil"></span></a>
<a href="javascript:if(confirm(\'Are you sure you want to delete this feature?\')) document.location = \'/admin/resources/php/product-features.php?p=delete&pfid=', $row['product_feature_id'], '\'" class="ui-state-default ui-corner-all left"><span class="ui-icon ui-icon-close"></span></a>
</div>';
$this->printProductFeaturesTable($row['product_feature_id'], $level + 1);
echo ' </td>
</tr>';
}
if($level != 0)
echo '</tbody></table>';
} else
if($product_feature_parent_id == 0)
echo '<tr><td align="center" colspan="2">Nici o specificatie de produs adaugata momentan!</td></tr>';
}
但结果不是上面的例子,而是:
1. Test
1. Test subcategory
2. Test subcategory 2
3. 6008-2 test // this is the last inserted row.. but where is the other one???
提前谢谢你 好的。。我刚刚发现唯一的问题是我的眼睛,正如你所看到的那样,我正在按
产品_功能_顺序
对结果排序,在本例中默认为0
所以问题是它们的显示顺序与插入id的顺序不一致,这让我很困惑
谢谢你抽出时间 您是否直接在应用程序之外的数据库上运行查询?我怀疑您会发现这是一个渲染问题,您正在跳过输出中的该行,原因是-由于$level检查,您可能正在跳过该记录。谢谢您的评论。。我已经这样做了,结果是一样的:(
从product_features\u id,product_feature\u name FROM product_features,其中product_feature\u parent\u id='1'ORDER BY product_feature\u ORDER
父\u id列是varchar吗?如果是,可能是因为其中一行中有一个空格或另一个不可见的字符吗?父\u id
是bigint(20)
1. Test
1. Test subcategory
2. Test subcategory 2
3. 6008-2 test // this is the last inserted row.. but where is the other one???