Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Date: Sun, 15 Jun 2014 20:01:38 +0200 From: Luuk User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 Newsgroups: comp.lang.php Subject: Re: How to loop through the dates? References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <2l317b-4cc.ln1@luuk.invalid.lan> Lines: 99 NNTP-Posting-Host: 2001:980:9089:1:6c7b:5d73:47a8:ba0b X-Trace: 1402855802 news.xs4all.nl 2958 [2001:980:9089:1:6c7b:5d73:47a8:ba0b]:38231 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.php:13862 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. >