sql - mysql group by php concat -
sql - mysql group by php concat -
i have table of fixtures in db: hometeam, awayteam, date, time
i using mysql_fetch_array
, getting following:
hometeam awayteam date time -------------------------------------------- blackburn wolves 13/08/2011 3:00pm arsenal liverpool 13/08/2011 3:00pm etc
i want return:
13/08/2011 --------------------------- blackburn, wolves, 3:00pm arsenal, liverpool, 3:00pm etc
i have tried grouping date, returns 1 fixture date rubbish.
i have tried group_concat
, problem need modify items in group, such changing time format server time readable time above.
you can sort date , check in php when date changes between 2 rows. this:
function h($s) { homecoming htmlspecialchars($s); } $conn = mysqli_connect(…); $result = mysqli_query($conn, 'select * fixtures order date'); $lastdate = null; while(($row = mysqli_fetch_assoc($result)) !== false) { if($lastdate != $row['date']) { // output date divider/header echo '<h1>',h($row['date']),'</h1>'; $lastdate = $row['date']; } echo h($row['hometeam']), ', ', h($row['awayteam']), ', ', h($row['time']); }
mysql sql group-by
Comments
Post a Comment