Jump to content

Recommended Posts

i came up with this, if any one know a better way please let me know.

 

function newSongs($limit){

$select="SELECT DATE_FORMAT(date,'%a, %M %d, %y') as dates FROM tra_artist_song GROUP BY dates LIMIT $limit";
$query=mysql_query($select)or die(mysql_error());

while($name=mysql_fetch_array($query)){
$dates=$name['dates'];

echo '<h3>'.$dates.'</h3>';
$select2="SELECT song_name FROM tra_artist_song WHERE DATE_FORMAT(date,'%a, %M %d, %y')='$dates'";
$query2=mysql_query($select2)or die(mysql_error());

while($songNames=mysql_fetch_array($query2)){
echo $songNames['song_name'].'<br />';
}

}

}

Link to comment
https://forums.phpfreaks.com/topic/64601-solved-group-by-date/#findComment-322175
Share on other sites

try

<?php
$select="SELECT DATE_FORMAT(date,'%a, %M %d, %y') as dates, song_name FROM tra_artist_song ORDER BY dates LIMIT $limit";
$query=mysql_query($select)or die(mysql_error());

$prevdate = '';
while (list($dt, $song) = mysql_fetch_row($query)) {
    if ($prevdate != $dt)
    {
        echo "<h3>$dt</h3>";       // output date when its value changes
        $prevdate = $dt ;
    }
    echo "$song<br/>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/64601-solved-group-by-date/#findComment-322214
Share on other sites

and less query traffic. You could also do this

 

<?php
$select="SELECT DATE_FORMAT(date,'%a, %M %d, %y') as dates,
        GROUP_CONCAT (song_name SEPARATOR '<br/>') 
        FROM tra_artist_song 
        GROUP BY dates LIMIT $limit";
$query=mysql_query($select)or die(mysql_error());

while (list($dt, $songs) = mysql_fetch_row($query)) {
    echo "<h3>$date</h3>$songs";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/64601-solved-group-by-date/#findComment-322777
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.