473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Multi Query Issue

91
I have 3 tables I need to get data from. Which as fields I need from each.

opencases_daily - Assigned_To, Prov_Group
tsms - Group, Name
prov_groups - gid, group_name

The opencases_daily has multiple entries with the tsms.Name in it. However I will specify the Prov_Group and need to get the count each time the Prov_Group= what i specify for the Assigned_To. So Jack could have multiple entries in opencases daily but I need the number of times he appears in there with the Prov_Group = 1234 but only if he is in tsms. This works good however there are some rows in opencases_daily that have the Assigned_To blank or they do not exist in tsms in which case I want to make their name 'Other' so I can display it as a name with Jack.

Here is the code I have so far but can anyone think of how I can have it change anyone with Prov_Group = 1234 and their name is not in tsms then it will increment 'Other'?

Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT * FROM tsms ORDER BY `Name`";
  2.  
  3.         $sql = $db->query($sql);
  4.         if(is_numeric($_REQUEST[2]))
  5.         {
  6.             $group = $func->groupNum2Name($_REQUEST[2]);
  7.         }
  8.         while ($res = $db->fetchArray($sql,MYSQL_ASSOC))
  9.         {
  10.  
  11.             $sql3 = "SELECT COUNT(*) FROM opencases_daily WHERE ".
  12.                 "DATEDIFF(CURDATE(),STR_TO_DATE(Last_Out_Note, '%m/%d/%y')) ".
  13.                 ">= 6 AND `Assigned_To`='".$res['Name']."'".
  14.                 $func->iif(is_numeric($_REQUEST[2]),' AND `Prov_Group`=\''.$group,'')."'";
  15.                 $sql3 = $db->query($sql3);
  16.  
  17.             $num = $db->result($sql3);
  18.             # Check if there are events for the user.
  19.             if ($num > 0)
  20.             {
  21.                 // Assign data for pie chart
  22.                 $data[] = $num;
  23.                 $targets[] = "javascript:LoadData('/tsm/".$res['uid']."')";
  24.                 $lbl[] = $res['Name'];
  25.                 $alts[] = "Events %d";
  26.             }
  27.         }
Apr 2 '08 #1
3 1593
arggg
91
anyone know of a way to do this?
Apr 2 '08 #2
pbmods
5,821 Expert 4TB
Heya, Arggg.

I'm not sure I understand what you're trying to accomplish. Can you give an example of what 'correct' output might look like?
Jun 27 '08 #3
coolsti
310 100+
It is quite possible that you can perform what you wish in one (or maybe a few) simple queries.

For people to help you with that, however, you should post the structure of the tables, and then a short description of the update that you are attempting. If the tables are very large (many columns) you can always just post here the ones that are essential for us to understand how to help you.

Try posting the table structure (or abbreviated table structure) with the "create table" syntax, for example as a copy-paste of the "show create table" command. Then someone like myself can copy/paste into a test database and try some things.
Jun 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Matthias Braun | last post by:
Help! Probably it is too easy, but I am not so experienced in MySQL up to now. I have two tables table1&table2 with the following columns: col1 double, col2 int(11), col3 date I want to...
4
by: MSD | last post by:
I am running a report that uses a query as its record source and opens a form collecting beginning and ending item numbers to feed to the query. This works, but now I'm trying to use the result of...
0
by: Ellen Ricca | last post by:
I have an Access db with several ODBC linked ORACLE tables. These tables have multiple-field PK's. The tables work just fine in many diff types of queries including unmatched queries that are...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
2
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
4
by: Andy_Khosravi | last post by:
I'm trying to build a search utility for users to find 'inquiries' in my database that involves several tables. This is normally easy to do with the query builder, but I have a unique situation...
2
by: Rink Web Site Developer | last post by:
Hello, I am currently having a bug with a MYSQL query for an online calendar I am writing. I have been looking at this bug for a couple days now and am still not able to figure out why it...
14
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its...
9
by: zmickle | last post by:
Experts and books all say that you can share an Access back end on a shared drive with the front end running on each host computer. I have a simple database that tracks student data and it is...
1
by: vgarzon | last post by:
Hi, I'm having issues setting a multi-column combobox in the right way. What I'm trying to do is that when I click on a table (access 2007 subform), a form should fill with the values of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.