Max Posted February 5, 2020 Share Posted February 5, 2020 Hi Larry and everyone, I have really painted myself into a corner with this one. Above is the database that I created for a timeline. The issue is that not all of the dates at my disposition have days and months. Some are just years. Hence, I had to make a separate column for years only. What I want to do is create a timeline using tables so that any year that has either a YYYY date and/or a YYYY-MM-DD date appears in chronological order. I tried it with a for loop starting at $i = 1700 - 2000 which works for the first year but the while ($enquiry3 = @mysqli_fetch_array($enquiry2)) { will only iterate once and then stops. The alternative is to use MySQL such as: for($i = 1700; $i <= 2000; i++) { $enquiry = "SELECT * from Timeline WHERE Year = $i ORDER BY Year ASC" } which works OK for getting the year only files. Then we need to get the full date files so we try: for($i = 1700; $i <= 2000; i++) { $enquiry = " SELECT * from Timeline WHERE Date = YEAR($i, %Y) ORDER BY Date ASC" } ....but the date function doesn't seem to work. Any ideas??? Regards Max Link to comment Share on other sites More sharing options...
Max Posted February 5, 2020 Author Share Posted February 5, 2020 OK, have just got it. There is no need to use YEAR() function as the Date column will accept SELECT * FROM Timeline WHERE Date LIKE '%$i%' SORT BY Date ASC All working now. www.gssr.es/timeline.php Adios! Link to comment Share on other sites More sharing options...
Recommended Posts