c_pattle Posted December 15, 2011 Share Posted December 15, 2011 I was just wondering if there is a way to get the next row in advanced when looping through a mysql results. At the moment I have <? $i=1; ?> <? foreach ($query->result() as $row): ?> <?= $row->order_id ?> <? $i++; ?> <? endforeach; ?> At the moment this just echo's the order_id in the row its currently looping through but is there a way to get the order_id of the next row in advance? The reason I want to do this is because if I know the order_id is going to change on the next row then I will want to echo something different. Thanks Link to comment https://forums.phpfreaks.com/topic/253232-codeigniter-mysql-result/ Share on other sites More sharing options...
jotorres1 Posted December 15, 2011 Share Posted December 15, 2011 Hi c_pattle, I haven't seen it done with objects, but it is possible with arrays. I would do the following: <?php $i=1; ?> <?php foreach ($query->result_array() as $row): ?> <?php echo $row['order_id']; ?> <?php $next = $query->next_row('array'); ?> // I placed array in param for it to return an array <?php $i++; ?> <?php endforeach; ?> Link to comment https://forums.phpfreaks.com/topic/253232-codeigniter-mysql-result/#findComment-1298143 Share on other sites More sharing options...
c_pattle Posted December 15, 2011 Author Share Posted December 15, 2011 Hi jotorres1 Thanks for your help again. Was exactly what I needed! Link to comment https://forums.phpfreaks.com/topic/253232-codeigniter-mysql-result/#findComment-1298167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.