I've got a bunch of updates throughout the years. What PHP do I need to use to sort them by 2012, 2013, 2014 years? - Also is there a way to group them, so I can display 2012 + 2013 together and 2014 seperately? Thank you.
What are these updates? Perhaps they are strings which you have stored in a database or perhaps they are file names? If it is a bunch of files you could use readdir() as explained here http://se1.php.net/readdir If the names of the updates have a similar structure or pattern you could use regex or maybe simply substr to get the year. If they all end with the year you could easily get the year with substr($updatename, -4); Then you could store all these updates in a multidimensional array where you could have the update name and it's year and then sort the array by year. Read more about sorting the arrays here http://www.php.net/manual/en/array.sorting.php If you could elaborate on your question it may be easier to give more specific help, I hope my answer helps!
thanks - I sort of got it working with this with the YEAR code: $query = "SELECT setslug,title,preview_image,short_description,date_live FROM sets WHERE YEAR(date_live) = '2014' AND bonus = '0' AND access = '0' ORDER BY date_live DESC LIMIT 0, $number_of_items"; Code (markup):
Nice! You could also consider using group by http://www.w3schools.com/sql/sql_groupby.asp GROUP BY date_live
Thanks man! I have a sort of on-topic question...I can't display an active row which I setup. The weird thing is on some pages it displays, on other it doesn't. The code is: <? if (!isset($_SESSION["userID"])) { ?> <?php if($row['open_archive'] == 1) { ?>1d <? } ?> <? } ?> Code (markup): - So in the users table if open_archive = 1 then 1d should display. I'm pretty sure it doesn't have to be in a session, but not sure why it's not active?
It is hard to say what the problem is. There doesn't seem to be anything wrong with the code you posted. But you should know that you are only displaying ld if the session variable userID is not set. It could be that you are calling session_start() on some pages or simply setting the $_SESSION["userID"] to something above your if statement.
Oops I just figured out in a few mins (spent many hours on it before!) using: <? if (isset($_SESSION["userID"])) { $query0 = "SELECT user_name, upgrade, freebie, loyal_access, open_archive, stream, exclusive FROM users WHERE userID='".$_SESSION["userID"]."'"; $result0 = doQuery($query0); $row = mysql_fetch_array($result0); ?> <?php if($row['open_archive'] == 1) { ?>1d <? } ?> <? } ?> Code (markup):