Jump to content


Photo

Order by month query


  • Please log in to reply
2 replies to this topic

#1 monkeybidz

monkeybidz
  • Members
  • PipPipPip
  • Advanced Member
  • 330 posts

Posted 01 May 2006 - 04:09 AM

I am trying to order by a certain month only, say January for instance. The current script calls all months available in database. Below is a part of the code i need help with.
$query = "SELECT a.starts FROM NAMEOFMYDATABASE_problem a WHERE 
            a.starts=starts ORDER BY a.starts ASC limit $offset, $limit"; 
            $result = mysql_query($query);
            $tmp_date = mysql_result($result,$i,"a.starts");
            $month = substr($tmp_date,4,2);
            $day = substr($tmp_date,6,2);
            $year = substr($tmp_date,0,4);
            $date = "$month/$day/$year";

What can i do to order data for january only since it uses a substr temp date?

Thanks in advance.

#2 radox

radox
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 01 May 2006 - 04:15 AM

just change your query to grab the month you need.

ie. for January

SELECT a.starts FROM NAMEOFMYDATABASE_problem a WHERE
a.starts=starts AND MONTH(a.starts)='1' ORDER BY a.starts ASC limit $offset, $limit

#3 monkeybidz

monkeybidz
  • Members
  • PipPipPip
  • Advanced Member
  • 330 posts

Posted 01 May 2006 - 05:12 AM

Thanks so much! I have been trying this for months, but through other methods that did not do what i wanted. It works just like i want now. I made a few more modifications, but it works.

Thanks again!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users