Re: how to store arrays in a db?
| From: | Ryan Adams | Date: | Mon, 19 Jun 2000 19:56:01 +0000 |
| Subject: | Re: how to store arrays in a db? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2237@lists.php.net to get a copy of this message | ||
One way to do it...
Set up your database like:
professors (prof_id varchar(8) not null primary key, name varchar(32), email varchar(128), phone
varchar(32), ...)
students (student_id varchar(8) not null primary key, name varchar(32), email varchar(128), phone
varchar(32), ...)
appointments (appt_id int auto_increment primary key, prof_id varchar(8),
start_time time, end_time time, date date, is_reserved smallint, reserved_by varchar(8))
Enter all professor information in professors.
Enter all student information in students.
Enter a row per available appointment (keyed by prof_id) in appointments with
is_reserved=0 and reserved_by null.
When a student reserves a time with a professor, update appointments as follows:
1. set is_reserved to 1 for that appointment
2. set reserved_by to the id of the student who is reserving the appointment
When the student is selecting an appointment, you could make a pulldown menu that uses
the appointment id (appt_id) as the value (the query for that might go something like
"select * from appointments where is_reserved=0"). Then step through that result set
to generate your pulldown menu.
echo "<select name=cappt_id>";
while ($a = mysql_fetch_array($that_query)) {
echo "<option value='$a[appt_id]'>$a[start_time] -
$a[end_time]</option>";
}
echo "</select>";
When the student submits that form, perform a query like
"update appointments set is_reserved=1, reserved_by='$student_id' where
appt_id='$cappt_id'"
to actually reserve the appointment. (This assumes that you are passing student_id around
in a session or something).
Another option would be to use serialize() to get the data into the field, but i'm not
sure that that will accomplish what you want it to.
Hope this helps,
Ryan
On Mon, Jun 19, 2000 at 02:09:58PM -0400, Erb, Maria wrote:
> thanks so much to everyone who responded to my earlier programming question
> with regard to the faculty online office hours scheduling project. I've
> taken a good suggestion and created an object to store all the info relating
> to the faculty members and the dates and times for their appointments. one
> question: how do I store this info in a db? I'm using mysql and when I set
> up a test table, i created a field to hold the appointment dates and another
> to hold the appointment times. These dates and times are both arrays with
> multiple entries. How can these be stored in a db?
>
> thanks so much!
> maria
>
> Maria B. Erb
> Web Developer
> Keene State College
> 603-358-2340
>
> mail address:
> MS 2707 / CMIT
> 229 Main Street
> Keene, NH 03435
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
---end quoted text---