I am having trouble. I am not sure if it is not possible or not, but don't know any alternatives.
I am converting my site from PHP and MYSQL to ASP.NET and MSSQL. In my current site. I did a query and then did another query on each record while looping through those results to get what I am trying to do in one query now. I would simply do that same thing but I am not sure how while using Visual Studio and I know that it was bad code, so thought I would fix it.
Here is my current setup:
event table definition in MySQL
+-----------------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+-------------+------+-----+---------+----------------+
| ev_id | smallint(6) | | PRI | NULL | auto_increment |
| st_id | smallint(6) | YES | | NULL | |
| re_id | smallint(6) | YES | | NULL | |
| ev_name | varchar(50) | | | | |
| ev_description | text | YES | | NULL | |
| ev_date | date | YES | | NULL | |
| ev_time | time | YES | | NULL | |
| lo_id | smallint(6) | YES | | NULL | |
| lc_id | smallint(6) | YES | | NULL | |
| ev_duration | varchar(10) | YES | | NULL | |
| ev_adultsattended | smallint(4) | YES | | NULL | |
| ev_youthattended | smallint(4) | YES | | NULL | |
| ev_staffattended | smallint(4) | YES | | NULL | |
| ev_residentsattended | smallint(4) | YES | | NULL | |
| ev_volunteersattended | smallint(4) | YES | | NULL | |
+-----------------------+-------------+------+-----+---------+----------------+
eventrating table definition in MySQL
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| ev_id | smallint(6) | | PRI | 0 | |
| st_id | smallint(6) | | PRI | 0 | |
| rlc_id | smallint(6) | YES | | NULL | |
| er_comment | text | YES | | NULL | |
| er_famrating | char(1) | YES | | NULL | |
| er_staffrating | char(1) | YES | | NULL | |
| er_resrating | char(1) | YES | | NULL | |
| er_volrating | char(1) | YES | | NULL | |
| er_repeat | varchar(5) | YES | | NULL | |
+----------------+-------------+------+-----+---------+-------+
PHP queries to get the data and place in a dropdown box
*** I am using a formcreator class that I built so the code will look a little different, but should be easy enough to follow ***
[PHP]$query = "select DISTINCT e.ev_id, e.ev_name, e.ev_date, s.st_username, s.st_id from event e, staff s, resource r where (e.ev_date >= '$start_date' and e.ev_date <= '$end_date' and s.st_id = e.st_id and r.re_id = e.re_id) ";//and (er.st_id != 1)";// and ".$user_id." <> ANY (select er.st_id from eventrating er) order by e.ev_name";
$result = mysql_query($query);
$select_event_array = array ();
$select_event_count = 0;
if (mysql_num_rows($result))
{
$select_event_array[$select_event_count] = array("label" => "", "value" => "^");
$select_event_count++;
while ($row = mysql_fetch_array($result))
{
$query2 = "select * from eventrating er where er.ev_id = ".$row[0]." and er.st_id = $user_id";
$result2 = mysql_query($query2);
if (mysql_num_rows($result2) == 0)
{
$select_event_array[$select_event_count] = array("label" => $row[1], "value" => $row[0]);
$select_event_count++;
}
}
}
else
{
$select_event_array[$select_event_count] = array("label" => "No Events", "value" => "^");
}
if ($select_event_count < 2)
{
$select_event_array[$select_event_count - 1] = array("label" => "No Events", "value" => "^");
}[/PHP]
So I am trying to do this in mssql. I have converted the tables over and here are the defenitions that I am currently using.
events table
ev_id | smallint <- primary
st_id | smallint
re_id | smallint
ev_name | varchar(50)
ev_description | varchar(489)
ev_date | datetime
ev_time | varchar(12)
lo_id | smallint
lc_id | smallint
ev_duration | varchar(10)
ev_adultsattended | smallint
ev_youtattented | smallint
ev_staffattended | smallint
ev_residentsattended | smallint
ev_volunteersattended | smallint
eventrating table
ev_id | smallint <- primary
st_id | smallint <- primary
rlc_id | smallint
er_comment | varchar(291)
er_famrating | varchar(1)
er_famrating | varchar(1)
er_staffrating | varchar(1)
er_resrating | varchar(1)
er_volrating | varchar(1)
er_repeat | varchar(5)
The staff id in the event table is for the staff member responsible for the event, while the staff id in the eventrating table is for the staff member who is rating the event. There can be many ratings on each event by staff members, but each staff member can only rate each event once.
So, I am try to show all events within a certain date range that have not been rated by the current staff member logged in.
I may not have my database normalized very well and would take suggestions toward getting it in shape as well. I have a lot of limitations based on the fact that I am going to be importing the current data into the new database and don't want to have to convert data as well as much as possible.
Sorry if I have shared too much!
Thanks!