Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql table display using php

Status
Not open for further replies.

akaballa123

Technical User
Apr 29, 2008
46
US
Hi,

I am trying to create this scenario where I can create a table that display all the trainings that each particular organization provides.

I have two mysql tables related to this. I fetched the organization names from the orgtbl and the training names from addtrainingtbl .

I want something outputting in excel essential something like this:

Organization Name Training Name

Org A T1
T2

Org B T3
T4
T5

etc.


I am displaying the organization names, but I am not able to retrieve the training names corresponding to the organizations. Following is my code:

Code:
else if ($_REQUEST['trainingOrg'])
{
     $orgT = @mysql_query('SELECT orgName FROM orgtbl');
     
     $filepnt3 = fopen("organizationalTrainingReport.xls", 'w+');
     $content3 = '<table cellpadding="10" border="1" width="30%">' ;
     $content3 .= ' <tr><td bgcolor = "blue" align="center"><b>' . 'Organization Name' . '</b></td>' . '<td bgcolor = "blue" align="center"><b>' . 'Training Name' . '</b></td> </tr>' ;
     
     while ($row = mysql_fetch_array($orgT))
     {
     
           $orgName = $row['orgName'];
           $content3 .= '<tr><td align="center">' . $orgName . '</td>' ;
           $trainingOrg = @mysql_query('SELECT trainingName FROM addtrainingtbl WHERE organization = \'$orgName\'');

           
           while($trn = mysql_fetch_array($trainingOrg))
           {
              $content3 .='<td align="center">' . $trn['trainingName'] . '</td></tr>';
           }
     }
     
     $content3 .= '</table>';
     fwrite($filepnt3, $content3);
     fclose($filepnt3);
     echo '<a href="organizationalTrainingReport.xls">Click here to download as Excel File</a>';
     echo '<br><br><a href ="genReport.php">Click here to go back to Generate Report</a>';
}

Plz Help!

Thanks!
 
start by getting rid of the @ signs.
use syntax like

Code:
$result = mysql_query($sql) or die(mysql_error());
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top