Re: How to loop through the dates? [message #186124 is a reply to message #186119] |
Sun, 15 June 2014 18:01 |
Luuk
Messages: 329 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 15-6-2014 19:40, Denis McMahon wrote:
> On Sun, 15 Jun 2014 12:11:01 -0400, richard wrote:
>
>> Data is ordered by date.
>
> See, this is where the richard database design starts to bite the richard
> arse.
>
> You are storing dates as a string representation of the date, so your
> "order by date" sql clause causes the data to be ordered according to the
> string collation for the relevant table.
>
> If you want the mysql rdbms to sort the data into date sequence, then you
> need to store the data as dates. The mysql rdbms sorts dates perfectly.
> It also sorts strings perfectly. But to sort dates it needs to know that
> they are dates, and you have told it that they are strings. Because you
> have told it that they are strings, when you ask it to sort them, it
> sorts them as strings. So the sorting rules it applies to a column of
> type datetime are different to the sorting rules it applies to a column
> of type [var]char.
>
> supposing you store the strings:
>
> '06/21/2013', '07/21/12013' and '06/21/2014'
>
> the sorted sequence will probably[1] be:
>
> '06/21/2013'
> '06/21/2014'
> '07/21/2013'
>
> [1] unless you have a weird collation defined
>
> Because in most 'western alphabet' character sorting sequences, 6 comes
> before 7, and ascii strings are sorted from left to right.
>
up until here, you did not visit the link to his site, which he gave,
and that's why above i see some things dat are not true.
The link is showing the date fields in the correct order:
01-06-2014
01-06-2014
01-06-2014
02-06-2014
02-06-2014
02-06-2014
02-06-2014
02-06-2014
02-06-2014
02-06-2014
02-06-2014
02-06-2014
03-06-2014
03-06-2014
03-06-2014
03-06-2014
03-06-2014
03-06-2014
03-06-2014
03-06-2014
03-06-2014
04-06-2014
04-06-2014
04-06-2014
04-06-2014
04-06-2014
04-06-2014
04-06-2014
04-06-2014
04-06-2014
> That aside, you don't seem to have actually described what the problem
> that you want fixed is this time, nor have you given examples of (a) what
> you expect to happen and (b) what is actually happening, so you'll not be
> surprised that we can't diagnose and resolve the issue, and are instead
> reduced to identifying, yet again, the generic flaws in your approach to
> coding.
@richard:
it's the link which gave an example, and some people (most of them) do
NOT want to follow a link to a website. It's much better to give a short
example of what's happening in the message with your problem, than
referring to a website.
>
> Instead of suppressing the error in the call to mysqli_num_rows, you
> should first test whether mysqli_query() returned an error flag. You have
> been told this several times.
>
> The mechanisms you're using to loop through the result set and the
> resulting array that you create are neither efficient or easy to follow.
>
> As far as I can see, your code can be replaced with about 12 lines of
> competently written php, with an extra 5 lines to add some comprehensive
> error reporting and user friendly error handling.
>
|
|
|