2012-05-09 28 views
0

我有一個數組包含庫存項目的「Category」,「Group」和「Subgroup」上的mysql查詢結果。我需要構建一個動態菜單,但是我正在構建的數組的當前行的內容取決於下一行中的列。如何在mysql結果中向前看

我查過了,發現了很多例子,但是他們都檢查了數組的整行(mysql行)我只想檢查數組行中的一個項目(一個mysql列)。我需要這樣的東西

for ($ix = 0; $ix < (length(current_result) - 1); $ix++) { 
    if (current_result[$ix, Catagory] = current_result[$ix + 1, Catagory]) { 
    echo some code 
    } else { 
    echo some other code 
    } 
} 
some code to handle the last line of the array 
+0

什麼導致你需要@約翰·哈特 –

回答

0

假設你有行的關聯數組,你只是缺少合適的數組語法:

for(....){ 
    $thiscat = $current_result[$ix]['Category']; 
    $nextcat = $current_result[$ix+1]['Category']; 
}