This should be simple, and I started out thinking it was, but now I'm at an impasse.
The background, I have a DB with a table where I store my current bikes. I also have a table where I store my current rides. I usually join the two tables on the bike_name
column as you'll see in my query below.
I had the silly goal of riding a century on each bike this year.
I want to create a status dashboard that has each bike with an icon indicating it's been done, green for yes, red for no.
Additionally, if it is yes, I want to populate the ride_date and ride_miles.
The second criteria is easy enough to do, the SQL query I have is:
SELECT r.bike_name,
r.ride_date,
r.ride_miles
FROM rides r
JOIN bikes b
ON r.bike_name=b.bike_name
WHERE DATE_FORMAT(r.ride_date, '%Y')='$current_year'
AND ride_miles > 100
The problem with this is it will only pull back rides (and the bikes) over 100. I can massage the data to make a red icon and post the relevant info. I can't populate the red icon for ones without 100 because I won't even know about them with my query. I've been sitting here trying to think about this and can't come up with a good solution. I just started messing with PHP this year, and while I've accomplished a lot, I think sometimes I might do it in convoluted ways.
The thought I had was that I could rewrite the SQL to ORDER BY
longest ride for each bike, get that data, then use logic within PHP to populate my info... Hmm, maybe that's what I need to do...