Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #13856 > unrolled thread
| Started by | richard <noreply@example.com> |
|---|---|
| First post | 2014-06-15 12:11 -0400 |
| Last post | 2014-06-15 20:59 -0400 |
| Articles | 8 on this page of 28 — 8 participants |
Back to article view | Back to comp.lang.php
How to loop through the dates? richard <noreply@example.com> - 2014-06-15 12:11 -0400
Re: How to loop through the dates? Luuk <luuk@invalid.lan> - 2014-06-15 18:38 +0200
Re: How to loop through the dates? Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-15 17:43 +0000
Re: How to loop through the dates? Luuk <luuk@invalid.lan> - 2014-06-15 20:03 +0200
Re: How to loop through the dates? Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-15 17:40 +0000
Re: How to loop through the dates? richard <noreply@example.com> - 2014-06-15 13:59 -0400
Re: How to loop through the dates? Luuk <luuk@invalid.lan> - 2014-06-15 20:27 +0200
Re: How to loop through the dates? Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-15 19:14 +0000
Re: How to loop through the dates? Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-06-15 21:39 +0000
Re: How to loop through the dates? Arno Welzel <usenet@arnowelzel.de> - 2014-06-17 08:12 +0200
Re: How to loop through the dates? Luuk <luuk@invalid.lan> - 2014-06-15 20:01 +0200
Re: How to loop through the dates? Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-15 19:07 +0000
Re: How to loop through the dates? Luuk <luuk@invalid.lan> - 2014-06-15 21:58 +0200
Re: How to loop through the dates? Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-16 00:55 +0000
Re: How to loop through the dates? richard <noreply@example.com> - 2014-06-16 13:02 -0400
Re: How to loop through the dates? Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-06-16 17:57 +0000
Re: How to loop through the dates? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-06-15 19:14 -0400
Re: How to loop through the dates? richard <noreply@example.com> - 2014-06-16 12:26 -0400
Re: How to loop through the dates? Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-06-16 16:39 +0000
Re: How to loop through the dates? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-06-16 14:14 -0400
Re: How to loop through the dates? Arno Welzel <usenet@arnowelzel.de> - 2014-06-17 08:18 +0200
Re: How to loop through the dates? Tim Streater <timstreater@greenbee.net> - 2014-06-15 20:30 +0100
Re: How to loop through the dates? Luuk <luuk@invalid.lan> - 2014-06-15 22:01 +0200
Re: How to loop through the dates? Tim Streater <timstreater@greenbee.net> - 2014-06-15 21:34 +0100
Re: How to loop through the dates? Luuk <luuk@invalid.lan> - 2014-06-15 23:32 +0200
Re: How to loop through the dates? richard <noreply@example.com> - 2014-06-16 12:19 -0400
Re: How to loop through the dates? Norman Peelman <npeelman@cfl.rr.com> - 2014-06-16 20:44 -0400
Re: How to loop through the dates? Norman Peelman <npeelman@cfl.rr.com> - 2014-06-15 20:59 -0400
Page 2 of 2 — ← Prev page 1 [2]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2014-06-17 08:18 +0200 |
| Message-ID | <539FDDA7.80100@arnowelzel.de> |
| In reply to | #13880 |
richard, 2014-06-16 18:26: > On Sun, 15 Jun 2014 19:14:22 -0400, Lew Pitcher wrote: > >> On Sunday 15 June 2014 13:40, in comp.lang.php, "Denis McMahon" >> <denismfmcmahon@gmail.com> 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. >> >> That's good advice (the best). >> >> However, richard can get away with >> SELECT * FROM table ORDER BY STR_TO_DATE(date,date_string_format); >> >> That will convert his string dates to "real" dates for the purposes of >> ordering the resultset rows, and should come out in ascending sequence by >> calendar date. >> http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date >> >> >> >> [snip] > > What is it with you people over this damn date issue? Because YOU said in your initial posting, that you use THIS statement: SELECT * FROM tracker ORDER BY date Now - if "date" is not a date type but just a text field, the ORDER BY clause will NOT work as intended: 01-07-1996 02-03-2010 10-10-1985 12-11-2014 You see - the order seems to be quite "random" - 1996, then 2010, then 1985 and finally 2014. This is caused by not using the date type for the column "date" - so the dates will just be treated as text and therefore ordered alphabetically but not by their date values. > I am only using date in the table as a unique identifier. No - you are also using the date to order stuff as shown in your first post. But I guess you even don't know what "ORDER BY" means nor what the concept of a "data type" is. -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de http://fahrradzukunft.de
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2014-06-15 20:30 +0100 |
| Message-ID | <150620142030411732%timstreater@greenbee.net> |
| In reply to | #13856 |
In article <ywx2wjj7uwar$.105qt7ftnicew$.dlg@40tude.net>, richard
<noreply@example.com> wrote:
> http://mroldies.net/radio/tracker2.php
>
>
> I've got my report generator almost completed.
> I only need to know how I can loop through the dates.
You haven't told us what the problem is you are experiencing.
> print $master[$i]['date'];
but from this I deduce that the dates are not coming out in the order
you expect (it's irritating to have to deduce what problem people are
experiencing. Cats, dogs, horses, etc, we forgive, because they can't
speak. You, OTOH, can. So please state, in future, what the problem is
and give *examples* of incorrect output).
My advice is not to store dates as strings (or even for whatever data
type mysql uses), but as integers, and use the number of seconds since
the epoch. You can use strtotime() to convert dates/times to a number
of seconds.
Then the sort will work properly.
Then for output,
echo date ('M jS, Y', $value);
will output the date in a suitable format.
--
"If you're not able to ask questions and deal with the answers without feeling
that someone has called your intelligence or competence into question, don't
ask questions on Usenet where the answers won't be carefully tailored to avoid
tripping your hair-trigger insecurities." - D M Procida, UCSM
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2014-06-15 22:01 +0200 |
| Message-ID | <1la17b-rhh.ln1@luuk.invalid.lan> |
| In reply to | #13866 |
On 15-6-2014 21:30, Tim Streater wrote:
> Then for output,
>
> echo date ('M jS, Y', $value);
>
> will output the date in a suitable format.
only if you live in a country where they put the month first......
here, where i live, the do day-month-year (15-06-2014)
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2014-06-15 21:34 +0100 |
| Message-ID | <150620142134190774%timstreater@greenbee.net> |
| In reply to | #13868 |
In article <1la17b-rhh.ln1@luuk.invalid.lan>, Luuk <luuk@invalid.lan>
wrote:
> On 15-6-2014 21:30, Tim Streater wrote:
> > Then for output,
> >
> > echo date ('M jS, Y', $value);
> >
> > will output the date in a suitable format.
>
> only if you live in a country where they put the month first......
>
> here, where i live, the do day-month-year (15-06-2014)
So do I. But richard appears to assume that his website is only to be
seen by Yanks. The string I put above for date is acceptable to me,
however, in as much as it leads to an unambiguous date such as:
Jun 8th, 2014
unlike:
06-08-2014
which certainly *is* ambiguous.
--
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2014-06-15 23:32 +0200 |
| Message-ID | <qvf17b-jrl.ln1@luuk.invalid.lan> |
| In reply to | #13869 |
On 15-6-2014 22:34, Tim Streater wrote:
> In article <1la17b-rhh.ln1@luuk.invalid.lan>, Luuk <luuk@invalid.lan>
> wrote:
>
>> On 15-6-2014 21:30, Tim Streater wrote:
>> > Then for output,
>> >
>> > echo date ('M jS, Y', $value);
>> >
>> > will output the date in a suitable format.
>>
>> only if you live in a country where they put the month first......
>>
>> here, where i live, the do day-month-year (15-06-2014)
>
> So do I. But richard appears to assume that his website is only to be
> seen by Yanks. The string I put above for date is acceptable to me,
> however, in as much as it leads to an unambiguous date such as:
>
> Jun 8th, 2014
>
> unlike:
>
> 06-08-2014
>
> which certainly *is* ambiguous.
>
it is not as ambiguous as you want it to be,
if the list is long enough .....
( more than 12 days should do )
[toc] | [prev] | [next] | [standalone]
| From | richard <noreply@example.com> |
|---|---|
| Date | 2014-06-16 12:19 -0400 |
| Message-ID | <wariilqzbp4i.bckec1l685n4.dlg@40tude.net> |
| In reply to | #13869 |
On Sun, 15 Jun 2014 21:34:19 +0100, Tim Streater wrote:
> In article <1la17b-rhh.ln1@luuk.invalid.lan>, Luuk <luuk@invalid.lan>
> wrote:
>
>> On 15-6-2014 21:30, Tim Streater wrote:
>>> Then for output,
>>>
>>> echo date ('M jS, Y', $value);
>>>
>>> will output the date in a suitable format.
>>
>> only if you live in a country where they put the month first......
>>
>> here, where i live, the do day-month-year (15-06-2014)
>
> So do I. But richard appears to assume that his website is only to be
> seen by Yanks. The string I put above for date is acceptable to me,
> however, in as much as it leads to an unambiguous date such as:
>
> Jun 8th, 2014
>
> unlike:
>
> 06-08-2014
>
> which certainly *is* ambiguous.
As y'all like to kindly point out, "Read the frickin manual!".
The options allow you to show the date in ANY format you want.
For my pusposes, I chose that format because the leading numbers will be
the first to change. Making it easier for the code to spot the changes.
As I learned to do in BASIC.
Sometimes, when you have a very long variable name, and only change the
last character to differenitate two variables, the machine may have
problems.
Now if you have the leading character change, no problems.
ThisisoeverylongstringnameA
ThisisoeverylongstringnameB
As compared to:
AThisisoeverylongstringname
BThisisoeverylongstringname
FYI, redcoat, my website that is visible to the public does not use this
format for dates.
I use this format ONLY in my tables.
Kindly note that on my home page, I show the format as
16th of June,2014.
[toc] | [prev] | [next] | [standalone]
| From | Norman Peelman <npeelman@cfl.rr.com> |
|---|---|
| Date | 2014-06-16 20:44 -0400 |
| Message-ID | <lno30l$o24$1@dont-email.me> |
| In reply to | #13879 |
On 06/16/2014 12:19 PM, richard wrote:
> On Sun, 15 Jun 2014 21:34:19 +0100, Tim Streater wrote:
>
>> In article <1la17b-rhh.ln1@luuk.invalid.lan>, Luuk <luuk@invalid.lan>
>> wrote:
>>
>>> On 15-6-2014 21:30, Tim Streater wrote:
>>>> Then for output,
>>>>
>>>> echo date ('M jS, Y', $value);
>>>>
>>>> will output the date in a suitable format.
>>>
>>> only if you live in a country where they put the month first......
>>>
>>> here, where i live, the do day-month-year (15-06-2014)
>>
>> So do I. But richard appears to assume that his website is only to be
>> seen by Yanks. The string I put above for date is acceptable to me,
>> however, in as much as it leads to an unambiguous date such as:
>>
>> Jun 8th, 2014
>>
>> unlike:
>>
>> 06-08-2014
>>
>> which certainly *is* ambiguous.
>
> As y'all like to kindly point out, "Read the frickin manual!".
> The options allow you to show the date in ANY format you want.
> For my pusposes, I chose that format because the leading numbers will be
> the first to change. Making it easier for the code to spot the changes.
>
As long as MySQL knows it's a proper date, you can do date *things*
with them...
> As I learned to do in BASIC.
> Sometimes, when you have a very long variable name, and only change the
> last character to differenitate two variables, the machine may have
> problems.
> Now if you have the leading character change, no problems.
>
> ThisisoeverylongstringnameA
> ThisisoeverylongstringnameB
>
PHP has no problem telling those apart...
As compared to:
> AThisisoeverylongstringname
> BThisisoeverylongstringname
>
or those for that matter.
> FYI, redcoat, my website that is visible to the public does not use this
> format for dates.
> I use this format ONLY in my tables.
> Kindly note that on my home page, I show the format as
> 16th of June,2014.
>
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[toc] | [prev] | [next] | [standalone]
| From | Norman Peelman <npeelman@cfl.rr.com> |
|---|---|
| Date | 2014-06-15 20:59 -0400 |
| Message-ID | <lnlfif$fcd$1@dont-email.me> |
| In reply to | #13856 |
On 06/15/2014 12:11 PM, richard wrote:
> http://mroldies.net/radio/tracker2.php
>
>
> I've got my report generator almost completed.
> I only need to know how I can loop through the dates.
> In BASIC, this is no big deal.
>
> As a synopsis,
> The table "tracker" is consulted for data.
> Data is ordered by date.
> Data is now transferred to the array $master.
> From $master, data is outputted as desired.
> In this case, each song played on a given date is listed.
>
>
>
>
> $query = "SELECT * FROM tracker ORDER BY date";
> $result = mysqli_query($con, $query);
> @$num_results = mysqli_num_rows($result);
>
> /*Loop through each row and display records */
> for($i=0; $i<$num_results; $i++) {
> $row = mysqli_fetch_assoc($result);
>
> $master[$i]['date']=$row['date'];
> $master[$i]['songID']=$row['songID'];
> $master[$i]['track']=$row['track'];
> $master[$i]['artist']=$row['artist'];
> $master[$i]['hits']=$row['hits'];
> }
>
> for($i=0;$i<$num_results;$i++){
>
> print $master[$i]['date'];
> echo "<br>";
> }
> echo "<table border=\"1\">";
>
> $newdate=$master[0]['date'];
>
> $ct=0;
> print "<tr><td>".$master[$ct]['date']."</td></tr>";
> while ($ct<$num_results){
>
> if ($master[$ct]['date']==$newdate) {
> print "<tr><td>".$master[$ct]['track']."</td></tr>";
> }
>
> $ct++;
> }
>
> echo "</table>";
>
>
> mysqli_close($con);
>
Since you don't appear to be doing anything with $master, why not
just output you table directly?
$query = "SELECT `date`, songID, track, artist, hits FROM tracker
ORDER BY `date` ASC";
$result = mysqli_query($con, $query);
if (!$result)
{
echo "The query failed with the following MySQL error:<br>";
echo mysqli_errno($con) . ": " . mysqli_error($con);
mysqli_close($con);
exit;
} else {
$num_results = mysqli_num_rows($result);
if ($num_results == NULL)
{
echo "No records to display!";
exit;
}
}
/*Loop through each row and display records */
$last_date = "nomatch";
$tmp = 0;
for($i=1; $i<$num_results; $i++)
{
$row = mysqli_fetch_assoc($result);
if ($row['date'] <> $last_date)
{ // ---------- new table ----------
if ($tmp == 1)
{ // ---------- end last table ----------
echo "</table>\n\r";
echo "<br>\n\r";
$tmp = 0;
}
if ($tmp == 0)
{ // ---------- start new table ----------
echo "<table border='1'>\n\r";
echo " <th colspan='3'>" . $row['date'] . "</th>\n\r";
$last_date = $row['date'];
$tmp = 1;
}
}
if ($row['date'] == $last_date)
{ // ---------- cell data ----------
echo " <tr>\n\r";
echo " <td>" . $row['songID'] . "</td>\n\r";
echo " <td>" . $row['track'] . "</td>\n\r";
echo " <td>" . $row['artist'] . "</td>\n\r";
echo " <td>" . $row['hits'] . "</td>\n\r";
echo " </tr>\n\r";
}
}
echo "</table>\n\r";
echo "<br>\n\r";
mysqli_close($con);
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.php
csiph-web