My database is populated by an online form, filled out by staff in event of an incident. The functionality that I am trying to provide is the ability to conduct analysis of incidents through analysis. If staff want to know about all of the incidents in a certain location, of a certain type, involving a particular patron, etc, they can collect those reports easily.
And I need all of the data for any given report, so I cannot distill it down to a new table.
Here are my tables:
create table [B]incident [/B](
incid int not null auto_increment primary key,
date date not null,
time time not null,
lid int not null,
otherpatrons varchar(255),
incdec text(255) not null,
police char(1),
tpa time,
inctypid int not null,
treatment varchar(100),
othertreat varchar(100),
transport varchar(100),
othertrans varchar(100),
actions text,
nonstaffinv text,
comments text,
staffinv text,
author varchar(30) not null)
Type=innodb;
create table [B]location[/B] (
lid int not null auto_increment primary key,
location varchar(25),
incid int not null,
index loc_data(lid),
foreign key (incid) REFERENCES incident(incid) ON DELETE CASCADE)
type=innodb;
create table [B]inctype[/B] (
inctypid int not null auto_increment primary key,
inctype varchar(100),
incid int not null,
index inct_data(itid),
foreign key (incid) REFERENCES incident(incid) ON DELETE CASCADE)
type=innodb;
create table [B]patrons[/B] (
pid int not null auto_increment primary key,
incid int not null,
lastname varchar(30),
firstname varchar(30),
street varchar(50),
city varchar(30),
state char(2),
zip int(5),
gender char(1),
age varchar(15),
height varchar(15),
weight varchar(15),
hair varchar(20),
eyes varchar(10),
race varchar(15),
other text,
foreign key (incid) references incident(incid) on delete cascade)
type=innodb;
So, my thinking is, since everything is based on the primary key of the incident table (incid), my first select statement needs to factor in the variables related to the various search functions available to the user (hence the conditional logic in building the query).
Once I have the incids for any search, I can use the foreach and separate queries for the different tables, to display the results.
Part of the problem that I have is, some of the queries are returning arrays: some incident reports can involve more than one incident type and more than one location.
nemonoman, I'm totally down for learning some intelligent programming and the joy of problem solving; that's why I'm here! 🙂 I have been working on debugging the SQL, and maybe that is my principal failure: I'm just not doing it right. I'll keep at it.
thanks all for the help.
spivey