Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15786
| From | Derek Turner <frderek@suremail.je> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Looking for NULL in arrays |
| Date | 2015-10-26 09:42 +0000 |
| Message-ID | <d96arrF7egqU1@mid.individual.net> (permalink) |
| References | <d94ctvFn9f4U1@mid.individual.net> <n0je5n$jqn$1@dont-email.me> |
On Sun, 25 Oct 2015 16:33:08 -0400, Jerry Stuckle wrote:
> I guess my first question is why are you fetching multiple rows into an
> array? There are valid reasons for it, but most of the time you just
> fetch a row and process it, then fetch the next row.
>
> The next question is why can it contain either three or five string
> values?
OK, thanks Jerry.
Probably best to say exactly what I'm trying to do, what I've found so
far and post the VERY 'work in progress' experimental code which is
running strictly on my local server :)
I'm doing a site for my local University of the Third Age. There are four
working pages here (but no DNS pointing to them as yet)
http://www.thozhiyur.org.uk/u3a/
If you view the Groups page you will see what information I have stored
about each group.
The task is to construct a diary of meetings for the next three months
from that information, not a trivial task. Playing with strtotime I've
discovered that it's terribly flaky an unpredictable, mostly because it
interprets "fifth Sunday of February" (for example) as '5th Sunday after
Feb 1st' rather than throwing an error as one might naively expect.
So I've found by experimenting that the most reliable way to get the
results I want is to supply a timestamp to strtotime to work from for
each month's results. It needs to be the last day of the previous month
to give reliable results.
The plan is to populate a temporary table of meetings which can then be
SELECTed from and ORDERed BY.
I will need to iterate through the 4 offsets (last day of previous month)
and through each of the string ordinals (3 or 5, may contains NULL values)
So here's the code so far:
//First get meeting information and perapare a table to receive it
$sql = "DROP TABLE IF EXISTS meetings ";
$drop = $mysqli->query($sql);
$sql = "CREATE TABLE meetings(groupName VARCHAR (50), meeting DATETIME);";
$create = $mysqli->query($sql);
$sql = "SELECT `name`,`weekday`,`time`,`ordinal1`,`ordinal2`,`ordinal3`
FROM `groups` WHERE `active` AND `time`";
$result = $mysqli->query($sql);
//Set up offsets for the ordinals - need to be last day of previous month
$month = date("m");
$year = date("Y");
$first = "$year-$month-01";
$first = strtotime($first) - 86400;
$month = $month + 1;
if ($month > 12) {
$year = $year + 1;
$month = "01";
}
$second = "$year-$month-01";
$second = strtotime($second) - 86400;
$month = $month + 1;
if ($month > 12) {
$year = $year + 1;
$month = "01";
}
$third = "$year-$month-01";
$third = strtotime($third) - 86400;
$month = $month + 1;
if ($month > 12) {
$year = $year + 1;
$month = "01";
}
$fourth = "$year-$month-01";
$fourth = strtotime($fourth) - 86400;
$offset = array($first, $second, $third, $fourth);
//now iterate through the groups and set up weeks of meetings
while ($row = $result->fetch_assoc()):
if ($row['ordinal1'] == "every") {
$weeks = array("first", "second", "third", "fourth", "fifth");
} else {
$weeks = array($row['ordinal1'], $row['ordinal2'], $row
['ordinal3']);
}
echo $row['name'] . " meets on " . $row['weekday'] . "<br><pre>";
print_r($weeks);
echo "</pre><br>";
endwhile;
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Looking for NULL in arrays Derek Turner <frderek@suremail.je> - 2015-10-25 16:05 +0000
Re: Looking for NULL in arrays Derek Turner <frderek@suremail.je> - 2015-10-25 16:11 +0000
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-25 19:07 +0100
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-25 19:06 +0100
Re: Looking for NULL in arrays Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-10-25 21:01 +0100
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-25 21:58 +0100
Re: Looking for NULL in arrays Jerry Stuckle <jstucklex@attglobal.net> - 2015-10-25 16:33 -0400
Re: Looking for NULL in arrays Derek Turner <frderek@suremail.je> - 2015-10-26 09:42 +0000
Re: Looking for NULL in arrays Jerry Stuckle <jstucklex@attglobal.net> - 2015-10-26 09:45 -0400
Re: Looking for NULL in arrays Derek Turner <frderek@suremail.je> - 2015-10-26 13:57 +0000
Re: Looking for NULL in arrays Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-10-26 17:41 +0100
Re: Looking for NULL in arrays Jerry Stuckle <jstucklex@attglobal.net> - 2015-10-26 12:49 -0400
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-26 22:25 +0100
Re: Looking for NULL in arrays Denis McMahon <denismfmcmahon@gmail.com> - 2015-10-27 03:16 +0000
Re: Looking for NULL in arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-27 22:23 +0100
csiph-web