Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Derek Turner Newsgroups: comp.lang.php Subject: Re: Looking for NULL in arrays Date: 26 Oct 2015 09:42:19 GMT Lines: 102 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net m3T4pdMOuHByaXNYW4pf6wBK6WrQ7uwvpGFVfAiPXAiyJh4m0U Cancel-Lock: sha1:cDEt3rYhN4QvvwjHFFaRNbUd+eo= User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.php:15786 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'] . "
";
    print_r($weeks);
    echo "

"; endwhile;