0
我有一個小問題,我找不到答案。輸出缺少行
我有一個表叫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???
謝謝在先進!
你是否直接針對應用程序之外的數據庫運行查詢?我懷疑你會發現這是一個渲染問題,並且由於某種原因你跳過輸出中的那一行 - 看起來你可能會因爲$ level檢查而跳過這條記錄。 – dash
感謝您的評論。我已經做到了這一點,結果都是一樣的:('SELECT PRODUCT_FEATURE_ID,product_feature_name \t \t \t \t \t \t \t \t \t \t FROM product_features \t \t \t \t \t \t \t \t \t \t WHERE product_feature_parent_id ='1' \t \t \t \t \t \t \t \t \t \t ORDER BY product_feature_order' –
是parent_id列a varchar?如果是這樣,可能是因爲在其中一行中有空格或其他不可見的字符? – richardtz