Jump to content

[SOLVED] sorting results by the week


bschultz

Recommended Posts

I have a "recipe of the day" section on a site.  All of the recipes are in the database.  I'd like to sort them by the week...

 

so like this:

 

friday week 2

thursday week 2

wednesday week 2

tuesday week 2

monday week 2

 

friday week 1

thursday week 1

wednesday week 1

tuesday week 1

monday week 1

 

So, after each Monday recipe, I want an extra line break.  The dates are in the db as type "date"...and I currently sort them date the date_column DESC.

 

I'm guessing that the easiest way would be to figure out the day of the week of each db entry, and if it's Monday, add the extra <br />. 

 

Any other ways (easier) to do this?

Link to comment
Share on other sites

Thanks kickstart...

 

<?php
$sql = "SELECT *, DATE_FORMAT(recipe_day, '%M %e %Y') as newrecipeday, DAYOFWEEK(recipe_day) as dayoftheweek FROM bitk ORDER BY recipe_day DESC";   	
$rs = mysql_query($sql,$dbc);  
$matches = 0; 
while ($row = mysql_fetch_assoc($rs))  {
$matches++; 

echo "<a href='/recipes.php?recipe_day=$row[recipe_day]'>".$row[newrecipeday]." "$row[title]"</a><br />"; 
if ($row[dayoftheweek] == 2){
echo "<br />";
}
}  
if (! $matches) { 
echo ("no matches"); 
}  
?>

 

did the trick.

Link to comment
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.