FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to loop through the dates?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: How to loop through the dates? [message #186119 is a reply to message #186117] Sun, 15 June 2014 17:40 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
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.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: What is the purpose of "&" in this code?
Next Topic: why is it always an endless loop?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 13:41:12 GMT 2024

Total time taken to generate the page: 0.04144 seconds