Okay, i have search everywhere on the web for this and i couldn't find it so i ask my problem here.
First i show you my code:
if ($result = $mysqli->query("SELECT * FROM jarig
WHERE maand = 'April'
ORDER BY datum"))
{
if ($result->num_rows > 0)
{
while ($row = $result->fetch_object()){
$date = new DateTime($row->datum);
echo "'" . $date->format('d') . " " . $row->naam;
echo "<br />";
}
}
}
My Problem:
As you see, i have a row that contains the names of the months of the year so i do not need to make more tables and easy to display because i can order it by months seperate. Also i have a row with the birthdates.
The birthdates (named as DATUM on the table) are in 'DATE' type on my table (i hope i say it right).
example The DATES in that row are as follow:
----------
DATUM
----------
1991-04-07
1978-04-12
2001-04-24
They are random filled in and that is with all the dates i stored in my database with birthdays.
The output as i liked to see on my website is kinda differently then how i wanted to have. The results are displayed only as days because it goes directly in the tablecell where they belong in html:
Calendar Month: April
'12 Jan
'07 kees
'24 Frans
My Question:
This happen on all the dates i have but i like to see that they are displayed from the first date in the month to the last date on the month in the right order and not randomly. Like i showed you above. Like to see them in this order, from lowest to highest numbers (07,12,24).
How do i fix this issue?
Maybe try to change your query:
SELECT jarig.*, DATE_FORMAT(jarig.datum, '%d') AS day FROM jarig
WHERE maand = 'April'
ORDER BY day
What you really need is just the day of the date, not the date in itself. So you can order by the day instead of the date.
Then in your php, just use the day column:
echo "'" . $row->day . " " . $row->naam;
echo "<br />";