loading a db table into a php array from mysql

2002-12-31 Thread David T-G
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi, all --

I'm so far about knee-deep in my project where I'll be using php to talk
to the mysql database and spit out my web pages.  I wonder if I should be
making individual calls to the database or loading a table into an array
so that I can walk it without those calls.

For instance, I have an instructors table, a clients table, and a
schedule table that has an instructor number column, a client number
column, and a time slot column.

In order to print an instructor's schedule for the day, I have to query
the instructors table to get the id where the name matches, and then
query the schedule table to get the clients and times where the time slot
matches some time today, and then I have to repeatedly query the clients
table to get the names where the returned id matches.  Since the schedule
should be arranged in time order, I might even have client 1 and then
client 2 and then client 1 again -- but I've already switched to 2 so I
have to start over for 1.

It seems a bit silly to, say, load the entire clients table into an array
because there could be thousands or millions of clients, but it's an
awful pain to go and make all of those mysql_query calls to walk the
clients list.  Should I just build a huge query something like

  $query = select fname,lname from clients where  ;
  foreach ($results_from_previous_query_somehow as $clinum)
{ $query .= id = '$clinum' or ; }
  $query .= id = '' ; # nice always-failing value; easier than pruning

and then query that way, to get all of what I need in one shot but not
the whole table (unless I need it all)?  Does sql like big OR clauses
like that?

I don't know if this is a PHP or a MySQL question, so this once I've
posted it to both lists.  I'll also summarize to both.


TIA  HAND  Happy New Year

mysql query,
:-D
- -- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.7 (FreeBSD)

iD8DBQE+Eeq6Gb7uCXufRwARAvYVAJ95HQCrsZLO0JR3rW67kQlG55gnGwCg0qka
TFUrVgkkqiqez9gVeCNf0gY=
=n9im
-END PGP SIGNATURE-

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




SUMMARY - Re: loading a db table into a php array from mysql

2002-12-31 Thread David T-G
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi, all --

...and then David T-G said...
% 
% I'm so far about knee-deep in my project where I'll be using php to talk
% to the mysql database and spit out my web pages.  I wonder if I should be
% making individual calls to the database or loading a table into an array
% so that I can walk it without those calls.

A little RTFMing later, after some helpful pointers, our hero returns.
Gee, look what a complex join can do for me:

  mysql select substring(s.timeslot,1,13),i.fname,concat(c.fname,'
  ',c.lname) from personnel as i, clients as c, schedule as s where i.id
  = s.instr and c.id = s.client and i.fname = 'penelope' order by
  timeslot;
  ++--+-+
  | substring(s.timeslot,1,13) | fname| concat(c.fname,' ',c.lname) |
  ++--+-+
  | 2002-12-27 06  | penelope | david t-g   |
  | 2002-12-27 07  | penelope | david t-g   |
  | 2002-12-27 08  | penelope | laura t-g   |
  | 2002-12-27 10  | penelope | david t-g   |
  ++--+-+
  4 rows in set (0.00 sec)

All of what I want in one single call :-)  I'll probably have to refine
this a bit as I learn more about how to use it, but I'm on my way.


Thanks again  HAND  HNY

mysql query,
:-D
- -- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.7 (FreeBSD)

iD8DBQE+Ef15Gb7uCXufRwARAiumAKCeJaDVTj2lULSiguWUhueZ33nQAQCgm8df
MY7UobhF+klun/sBa9RF4jY=
=6NDi
-END PGP SIGNATURE-

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php