selecting from more than one table
Posted: Mon Aug 22, 2005 1:58 pm
I have a file that downloads certain fields of a table. I want to combine 4 tables into one download file, but I can't get it to work with more than one table at a time. Each table is the same in structure. One is for the Administrative Team, one is for Improvements Team, etc., all of the fields are the same, just the row information is different. Is there a way to combine all tables into one download?
If I select FROM adminticket_tbl, improveticket_tbl, final_ticket, plattingticket_tbl I get the following error
If I select FROM adminticket_tbl, improveticket_tbl, final_ticket, plattingticket_tbl I get the following error
here is the code I have to download one table to an excel file...<br />
<b>Warning</b>: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in <b>/mylocationoffile/openticketdownload.php</b> on line <b>16</b><br />
<br />
<b>Warning</b>: mysql_num_fields(): supplied argument is not a valid MySQL result resource in <b>/mylocationoffile/openticketdownload.php</b> on line <b>17</b><br />
<br />
<b>Warning</b>: mysql_num_fields(): supplied argument is not a valid MySQL result resource in <b>/mylocationoffile/openticketdownload.php</b> on line <b>19</b><br />
<br />
<b>Warning</b>: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in <b>/mylocationoffile/openticketdownload.php</b> on line <b>23</b><br />
Code: Select all
<?PHP
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=jvtewaadminopentickets.xls");
header("Pragma: no-cache");
header("Expires: 0");
// DEFINE DB ELEMENTS
define(db_host, "myhostname");
define(db_user, "myuser");
define(db_pass, "mypassword");
define(db_link, mysql_connect(db_host,db_user,db_pass));
define(db_name, "mydatabasename");
mysql_select_db(db_name);
// QUERY DB FOR SELECTED DATA
$select = "SELECT task_id, ticket_shortname, ticket_date_opened, ticket_assigned_to, ticket_assigned_by, ticket_information FROM adminticket_tbl WHERE ticket_date_closed IS NULL";
$export = mysql_query($select);
$row_export = mysql_fetch_assoc($export);
$fields = mysql_num_fields($export);
$count = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
echo $header."\n".$data;
//IF STATMENT THAT IS PRODUCED IF NO DATA IS PRESENT
if ($data == "") {
$data = "\n(0) Records Found!n";
}
?>