Jump to content

MySQL array problem


c_pattle

Recommended Posts

I have an array of data from a mysql result.  The problem I have is that I want to find out what the next row is going to be in advanced.  At the moment I have

 

while($row = mysql_fetch_assoc($rs) {

    echo 'Order ID: ' . $row['order_id'];

}

 

This just echo's out the order_id of the current row.  However I want to find out if the order_id on the next row is going to be the same or different.  If it's different I will want to echo out something else.

 

while($row = mysql_fetch_assoc($rs) {

    echo 'Order ID: ' . $row['order_id'];

    //If order_id + 1 is different then echo
   echo 'Total: ' . $row['total']

}

 

Does anyone know a way round this problem?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/253234-mysql-array-problem/
Share on other sites

You remember the last value and detect when it changes. See the logic in this post - http://www.phpfreaks.com/forums/index.php?topic=349740.msg1650897#msg1650897

 

See the places in that code where it has - (optionally) do what is needed to close out the previous/last section

Link to comment
https://forums.phpfreaks.com/topic/253234-mysql-array-problem/#findComment-1298144
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.