Re: How to loop through the dates? [message #186122 is a reply to message #186119] |
Sun, 15 June 2014 17:59 |
Mr Oldies
Messages: 241 Registered: October 2013
Karma:
|
Senior Member |
|
|
On Sun, 15 Jun 2014 17:40:43 +0000 (UTC), 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.
>
> 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.
>
> 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.
In this instance "date" in the line you left quoted, refers to a column
name.
What if it had been "hits" instead or "title"?
You guys are hell bent on this date issue you forget that columns can hold
any data in any manner.Regardless of their name.
The only two things the table cares about is, the data is either a string
or a numeric.
|
|
|