Advertisement

05.15.2008 at 07:30PM PDT, ID: 23407288
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

How to join several dataset from different table together and write it to the text file

Asked by firekiller15 in PHP Scripting Language, PHP and Databases

Tags:

PHP
Hi experts,
I need to retrieve dataset from three different table and write it to the text file.

i name my text file as example.txt

A table contain of field and this field will be header to the text file.

let say i have table named school,student,course

for my school table i have field like SchoolName,Address,PhoneNo
for my student table i have field like StudentID,Age,Address
for my course table i have field like CourseName,Units,CreditPoints

My insert query contains dataset such as

insert into school value('Imperial college','Imperial street','+15648797')
insert into school value('Tar college','Tar street','+15754566')
insert into student value('1546987',23,'carpenter street')
insert into student value('1546988',19,'Darlington street')
insert into CourseName value('English Intensive program','English101',0)
insert into CourseName value('Computer Science','database101',25)

In my text file i should have a header and dataset as example below

header -->"SchoolName"|"Address"|"PhoneNo"|"StudentID"|"Age"|"Address"|"CourseName"|"Units"|"CreditPoints"

dataset-->"Imperial college"|"Imperial street"|"+15648797"|"1546987"|"23"|"carpenter street"|"English Intensive program"|
          "English101"|"0"|"Tar college"|"Tar street"|"+15754566"|"1546988"|"19"|"Darlington street"|"Computer Science"|"database101"|"25"


I have done a code as in code snippet

The problem with this code is that it will not join the dataset from different table together.
It will output all the dataset from school then student follow by course.
The output of the code in code snippet as follows:

header --> "SchoolName"|"Address"|"PhoneNo"|"StudentID"|"Age"|"Address"|"CourseName"|"Units"|"CreditPoints"

dataset --> "Imperial college"|"Imperial street"|"+15648797"|"Tar college"|"Tar street"|"+15754566"|"1546987"|"23"|"carpenter street"|"1546988"|"19"|"Darlington street"||"English Intensive program"|"English101"|"0"||"ComputerScience"|"database101"|"25"

My current output is display all the row of school then all the row of student follow by all the row of course.

How to write the dataset into the text file where it will display first row of school JOIN first row of student JOIN first row of course


Thanks for help
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
function GetHeader()
{
  $rw=$row;
  $headertofile = array ('SchoolName'|'Address'|'PhoneNo'|'StudentID'|'Age'|'Address'|'CourseName'|'Units'|'CreditPoints');
  
  $fileheader = implode("|",$headertofile); 
  $file = fopen('c:\example.txt', 'w');
  fputcsv($file, $headertofile, '|');
  fwrite($file, $fileheader);
  fclose($file);
}
 
 
function GetSchool()
{
   $query = "select * from School";
   			   
  $result = mysql_query($query);
  if(!$result) die("Query didn't work. " . mysql_error());
 
  $file = fopen('c:\example.txt', 'a');
  while($row = mysql_fetch_array($result))
  {
  fputcsv($file, $row, '|');
  }
 
  fclose($file);
  mysql_close($dbLink);
}
 
function GetStudent()
{
   $query = "select * from Student";
   			   
  $result = mysql_query($query);
  if(!$result) die("Query didn't work. " . mysql_error());
 
  $file = fopen('c:\example.txt', 'a');
  while($row = mysql_fetch_array($result))
  {
  fputcsv($file, $row, '|');
  }
 
  fclose($file);
  mysql_close($dbLink);
}
 
function GetCourse()
{
   $query = "select * from Course";
   			   
  $result = mysql_query($query);
  if(!$result) die("Query didn't work. " . mysql_error());
 
  $file = fopen('c:\example.txt', 'a');
  while($row = mysql_fetch_array($result))
  {
  fputcsv($file, $row, '|');
  }
 
  fclose($file);
  mysql_close($dbLink);
}
[+][-]05.15.2008 at 07:54PM PDT, ID: 21579679

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 09:05PM PDT, ID: 21579910

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 06:52AM PDT, ID: 21582634

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.19.2008 at 08:01PM PDT, ID: 21603306

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.19.2008 at 08:01PM PDT, ID: 21603308

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, PHP and Databases
Tags: PHP
Sign Up Now!
Solution Provided By: firekiller15
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628