c_pattle Posted December 15, 2011 Share Posted December 15, 2011 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 More sharing options...
PFMaBiSmAd Posted December 15, 2011 Share Posted December 15, 2011 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 More sharing options...
kney Posted December 15, 2011 Share Posted December 15, 2011 <?php $test = ""; while($row = mysql_fetch_assoc($rs) { echo 'Order ID: ' . $row['order_id']; if($row['order_id'] == $test){ echo 'Total: ' . $row['total']; } $test = $row['order_id']; } ?> Link to comment https://forums.phpfreaks.com/topic/253234-mysql-array-problem/#findComment-1298150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.