答えが見つからない小さな問題があります。
product_features
次のフィールドで呼び出されるテーブルがあります。
product_features
----------------------
id parent_id name order added_date
問題は、同じ名前の 2 つの行を挿入したことです。
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 - PRIMARY INDEX - AUTO INCREMENT
し、parent_id - INDEX
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
4. 6008-2 test
ただし、上記の例の代わりに、結果は次のようになります。
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???
よろしくお願いします!