i m trying to extract multiple rows and print it in a single line in a web page.
My code - while ($line = mysql_fetch_array($app, MYSQL_ASSOC))
-
{
-
echo "<tr><td>";
-
echo "<a href=AssignedUpdateForm.php?app=".$line['App'].
-
">".$line['App']."</a></td>";
-
echo "<td>" . $line['firstName'] ." ". $line['surname'] . "</td>";
-
echo "<td>" . $line['ServerName'] . "</td>"; echo "</tr>";
}
outputs this: - Application employee Server
-
z a c
-
z b c
-
z a d
-
z b d
however i want it to output - Application employee Server
-
z a,b c,d
-
z a,b c,d
can someone help please
7 2625
What is the logic here? There are 4 different types of records, but you are compacting them into 2. What is the logic for this compacting? Why is it that you can compact unrelated a's, b's, c's, and d's, but not z's? You need to be more specific.
wel actually the relationship hea is that an application can be handled by more than one employee and an application can be located on more than one server.Thus the one to many relatinship.
For eg.
relationship between Application and Employee - Employee Application
-
john sales
-
mary sales
relationship between application and server - Server Application
-
Server A sales
-
Server B sales
-
when i do a select statement from the two tables to print in a single table, i get - Application Employee Server
-
sales john Server A
-
sales mary Server A
-
sales john Server B
-
sales mary Server B
-
However i want to print - Application Employee Server
-
sales john,mary Server A,Server B
Is that possible?
Probably, yes. Tell us what your table structure looks like and the query that you are currently using.
My table structure is as follows: - DROP TABLE IF EXISTS employee;
-
CREATE TABLE employee(
-
emp_id VARCHAR(5) NOT NULL,
-
firstName VARCHAR(30) NOT NULL,
-
surname VARCHAR(30) NOT NULL,
-
TelephoneNumber VARCHAR(7),
-
Email VARCHAR(30),
-
username VARCHAR(30),
-
password VARCHAR(256),
-
CONSTRAINT emp_pk_EDPnum PRIMARY KEY(emp_id));
-
-
DROP TABLE IF EXISTS Application;
-
CREATE TABLE Application(
-
App VARCHAR(30) NOT NULL,
-
AppName VARCHAR(60) NOT NULL,
-
AppDescription VARCHAR(180),
-
YearDeveloped YEAR(4),
-
Development_Language VARCHAR(30),
-
Comments VARCHAR(120),
-
SectionID INT NOT NULL,
-
DBID INT NOT NULL,
-
CONSTRAINT Application_pk_App PRIMARY KEY(App),
-
CONSTRAINT Application_fk_SectionID FOREIGN KEY(SectionID) REFERENCES Section(SectionID),
-
CONSTRAINT Application_fk_DBID FOREIGN KEY(DBID) REFERENCES DB(DBID));
-
-
DROP TABLE IF EXISTS App_emp;
-
CREATE TABLE App_emp(
-
App_empID INT NOT NULL AUTO_INCREMENT,
-
emp_id VARCHAR(5) NOT NULL,
-
App VARCHAR(30) NOT NULL,
-
CONSTRAINT AppSupp_pk_AppSuppID PRIMARY KEY(App_empID),
-
CONSTRAINT AppSupp_fk_EDPnum FOREIGN KEY(emp_id) REFERENCES SupportPersonnel(emp_id),
-
CONSTRAINT AppSupp_fk_App FOREIGN KEY(App) REFERENCES Application(App));
-
-
DROP TABLE IF EXISTS Server;
-
CREATE TABLE Server(
-
ServerName VARCHAR(60) NOT NULL,
-
RackNum INT NOT NULL,
-
NetworkStatus INT,
-
ProcessorSpecification VARCHAR(90),
-
Memory INT,
-
AvailableMemory INT NOT NULL,
-
OperatingSystem VARCHAR(60),
-
OS_version VARCHAR(60),
-
LogonServer VARCHAR(30),
-
BIOSversion VARCHAR(30),
-
Remarks VARCHAR(60),
-
App VARCHAR(30),
-
CONSTRAINT Server_pk_ServerName PRIMARY KEY(ServerName),
-
CONSTRAINT Server_fk_App FOREIGN KEY(App) REFERENCES Application(App));
-
- <?php
-
// build query
-
$qry = "Select firstName, surname, App_emp.App, ServerName from employee,App_emp,".
-
"Server where App_emp.emp_id=employee.emp_id and App_emp.App=Server.App";
-
-
//execute query
-
$app = execute_query($qry) or die('Query failed: ' . mysql_error());
-
-
// write a loop to print out the results.
-
while ($line = mysql_fetch_array($app, MYSQL_ASSOC))
-
{
-
echo "<tr><td>";
-
echo "<a href=AssignedUpdateForm.php?app=".$line['App'].
-
">".$line['App']."</a></td>";
-
echo "<td>" . $line['firstName'] ." ". $line['surname'] . "</td>";
-
echo "<td>" . $line['ServerName'] . "</td>";
-
echo "</tr>";
-
}
-
?>
Would you mind showing the database structure in a tabular format? All of us who help you here do so on our own time, and sorting through your CREATE TABLE query isn't exactly fun. :P
I have attached the databse structure.
Not what I meant, but at least you've shown the relationships.
Servers have an application, applications can have multiple employees, and employees and can have multiple applications. And you want to merge all employees and applications by server?
I can't think of a way to make that into an atomic query. You'll have to use logic to merge the data together in the loops prior to output. Here's some semi-usable code, using implode(): - $currentServer = null;
-
$applications = array();
-
$employees = array();
-
-
while ($data = next MySQL row) {
-
if ($currentServer && $currentServer != $data->server) {
-
// output table row here using implode() on the arrays
-
-
$applications = array();
-
$employees = array();
-
} else {
-
$applications[] = $data->application;
-
$employees[] = $data->employee;
-
}
-
-
$currentServer = $data->server;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steven An |
last post by:
Howdy,
I need to write an update query with multiple aggregate functions.
Here is an example:
UPDATE t
SET
t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ),
t.b = ( select sum(f.q)...
|
by: Robert |
last post by:
Hi All,
I'm trying to solve this for a few days now and I just can't figure it
out...
I have three tables set up, I'll simplify them for this question:
Table 1: HOTELS
Columns: HOTEL_ID,...
|
by: R. P. |
last post by:
Anybody knows a way to produce output from a SELECT statement on a
single line, instead of each hit on a separate line?
Here is what I mean: let's say I have a table listing families, one per...
|
by: Lucius |
last post by:
Hello everyone, I have a query problem.
I'll put it like this. There is a 'publishers' table, and there is a
'titles' table. Publishers publish titles (of course). Now I want to make a
query (in...
|
by: Jay |
last post by:
Hi All,
My users are complaining about the page refreshing when they are
selecting multiple rows in a datagrid. Has anyone tried to manage this
using javascript?
I tried smartnavigation but that...
|
by: Bob Loveshade |
last post by:
I am looking for an example that shows how to select and highlight
multiple rows in a DataGrid.
My DataGrid is part of a Web User Control which is contained in an ASPX
page.
I haven't been...
|
by: Dave Edwards |
last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot
figure out how to fill a dataset with the same query but run against
multiple SQL servers, the query , table structure...
|
by: mark |
last post by:
I can't seem to get the logic for printing multiple pages. I know I have to
do a comparison between the bottom margin and the position of the next line
to be printed and initiate a has more pages...
|
by: Andy |
last post by:
Hi Gang
I have a simple single table that has many duplicate rows in them. The
distinctrows only works on more than one table. Is there a quick and
easy way to select only the distict rows...
|
by: Martin Joergensen |
last post by:
Hi,
I have some files which has the following content:
0 0 0 0 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 0 0 0 0 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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |