skyer2000 Posted March 20, 2008 Share Posted March 20, 2008 I have the following MySQL query SELECT * FROM table ORDER BY formtimestamp There are about 10-20 rows that have the same formtimestamp, and I want those to be seperated visually form the other formtimestamps (with new lists). However, when this pulls in results, everything is clumped together. Is there a way in PHP that will make a break when the formtimestamp changes? Link to comment https://forums.phpfreaks.com/topic/97130-breaking-up-mysql-results-with-php/ Share on other sites More sharing options...
p2grace Posted March 20, 2008 Share Posted March 20, 2008 I'd just do a check while you're looping through the results. Save the current timestamp into a variable and then on the next iteration check to see if the current timestamp is the same as the variable from the prior, if it isn't do a break. Link to comment https://forums.phpfreaks.com/topic/97130-breaking-up-mysql-results-with-php/#findComment-497000 Share on other sites More sharing options...
rhodesa Posted March 20, 2008 Share Posted March 20, 2008 the code would look like... <?php $sql = "SELECT * FROM table ORDER BY formtimestamp"; $result = mysql_query($sql); $last = null; while($row = mysql_fetch_assoc($row)){ if($last && $row['formtimestamp'] != $last){ print "<hr>"; //Do break stuff here $last = $row['formtimestamp']; } //print $row stuff here } ?> Link to comment https://forums.phpfreaks.com/topic/97130-breaking-up-mysql-results-with-php/#findComment-497001 Share on other sites More sharing options...
p2grace Posted March 20, 2008 Share Posted March 20, 2008 Yeup exactly. Link to comment https://forums.phpfreaks.com/topic/97130-breaking-up-mysql-results-with-php/#findComment-497003 Share on other sites More sharing options...
skyer2000 Posted March 20, 2008 Author Share Posted March 20, 2008 Why didn't I think of that haha, thanks for the help! Link to comment https://forums.phpfreaks.com/topic/97130-breaking-up-mysql-results-with-php/#findComment-497019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.