Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8995
| Message-ID | <19819803.o9xVrzyPd8@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2013-04-07 17:14 +0200 |
| Subject | Re: comparing arrays |
| Newsgroups | comp.lang.php |
| References | <kjrlk6$8es$1@speranza.aioe.org> <5107815.Hu20eYApaJ@PointedEars.de> <kjru44$10b$1@speranza.aioe.org> |
bill wrote: > On 4/7/2013 9:37 AM, Thomas 'PointedEars' Lahn wrote: >> bill wrote: >>> I need to see if a patient has appointments with a >>> psychotherapist and a physician on the same day. >>> >>> I request the schedule of each therapist and each physician as >>> arrays of arrays: >>> time, patient_number, duration (note, the therapist/physician id >>> is not in the array) >>> They are non-associative arrays (numeric keys) >>> I might have 1..n physicians and 1..n therapists >>> I can generate arrays of physicians and arrays of therapists >>> […] >> >> You should probably do this in a relational database. But if you >> absolutely must do it in PHP, you can determine what the keys of your >> data are, and in which order you need them: the patient, the date, or the >> doctor. >> >> Then you can build from the records a “multi-dimensional array” (for lack >> of a better word) from which becomes apparent where there are schedule >> collisions. You can take advantage of the fact that PHP builds “multi- >> dimensional arrays” automatically if you add another index expression. >> >> For example, in a loop, >> >> $appointments[$patient_id][$date] = $doctor; >> >> would store the information that the patient with ID $patient_id has an >> appointment with $doctor on $date. Obviously it is very easy then to >> organize the data by different primary keys in different >> “multi-dimensional arrays” (which themselves may be elements of yet >> another array, to avoid >> extra variables). If an element of an array with an index already >> exists, there is the collision. > > It is actually slightly simpler as I only need to check for > "today". But is more complex in that I have two classes for > "doctor:" therapist or physician. Am I to understand that you need to consider only one patient, only one date, and cannot figure out how to filter your array of arrays to see that there are different kinds of doctors involved using these criteria? > By doing it in a db are you suggesting a temporary table, or > using the tables I have ? The latter, sort of. You would JOIN the tables you have and apply aggregation functions on the result (certainly not as Frank Steinmetzger suggested). If you would need to do this often, it would be a good idea to store the result in a TEMPORARY TABLE, if your DBMS supports that, or in general in a so-called “flat table”. People have also devised and implemented a rather elegant way of querying data without a database – Language-INtegrated Query (LINQ) – that you also might find useful. [1] Please trim your quotes. PointedEars ___________ [1] <http://stackoverflow.com/questions/5792388/is-there-something-in-php- equivalent-to-linq-in-c> -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
comparing arrays bill <william@TechServSys.com> - 2013-04-07 07:34 -0400
Re: comparing arrays Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-07 08:34 -0400
Re: comparing arrays bill <william@TechServSys.com> - 2013-04-07 10:00 -0400
Re: comparing arrays Frank Steinmetzger <frank.steinmetzger@stud.tu-ilmenau.de> - 2013-04-07 16:14 +0200
Re: comparing arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-07 17:13 +0200
Re: comparing arrays bill <william@TechServSys.com> - 2013-04-07 11:34 -0400
Re: comparing arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-07 21:33 +0200
Re: comparing arrays The Natural Philosopher <tnp@invalid.invalid> - 2013-04-07 16:01 +0100
Re: comparing arrays Frank Steinmetzger <frank.steinmetzger@stud.tu-ilmenau.de> - 2013-04-07 20:22 +0200
Re: comparing arrays Jerry Stuckle <jstucklex@attglobal.net> - 2013-04-07 14:18 -0400
Re: comparing arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-07 15:37 +0200
Re: comparing arrays bill <william@TechServSys.com> - 2013-04-07 09:59 -0400
Re: comparing arrays Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-07 17:14 +0200
Re: comparing arrays The Natural Philosopher <tnp@invalid.invalid> - 2013-04-07 15:59 +0100
csiph-web