How to look ahead in a mysql result
Pregunta
I have an array containing the results of a mysql query on "Category", "Group" and "Subgroup" for stock items. I need to build a dynamic menu but the content of the current line of the array I am building depends on a column in the next line.
I have looked up and found many examples but all of them check the whole line of the array (the mysql row) I only want to check one item in the line of the array (one mysql column). I need something like
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
Solución
Assuming you have an associative array of rows, you're simply missing proper array syntax:
for( .... ){
$thiscat = $current_result[$ix]['Category'];
$nextcat = $current_result[$ix+1]['Category'];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow