Aquí va jpinedo:
Código PHP:
<?php
require('sqlconfig.php');
$tabla = $HTTP_POST_VARS["tabla"];
$select=("SELECT transid AS TRANSID, DATE_FORMAT(time,'%d/%m/%Y %T') AS FECHA, username AS USERNAME, description AS DESCRIPTION, TRUNCATE(amount/10000000,3) AS AMOUNT, type AS TYPE FROM $tabla WHERE amount>0 OR amount<0 ORDER BY username,time");
$export = mysql_query($select) or die( "<strong><font color=red>La tabla $tabla no existe !!!<br>Table $tabla doesn't exist !!!<br>Puede volver a la página anterior para reintentar</strong></font>" );
//
$count = mysql_num_fields($export);
for ($i = 0; $i < $count; $i++) {
$header .= mysql_field_name($export, $i)."\t";
}
/*************************************************
Extracto datos, formateo y lo guardo en una
variable $data
/*************************************************/
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);
/********************************************/
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
/********************************************
Sección para el download automático
/********************************************/
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$bus$tabla$now.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
Pero tengo 30 tablas con diferente estructura... entonces tengo otro script donde la linea del select es:
Código PHP:
<?php
//
<?php
$select=("SELECT transid AS ORDEN, DATE_FORMAT(time,'%d/%m/%Y %T') AS FECHA, username AS USUARIO, description AS DESCRIPCION, TRUNCATE(amount/10000000,3) AS IMPORTE, type AS TIPO FROM $tabla WHERE amount>0 OR amount<0 ORDER BY username,time");
//
?>
Y otro donde es:
Código PHP:
<?php
//el resto es igual al código "1"
$select=("SELECT rid AS RID, uid AS UID, TRUNCATE(amount/10000000,2) AS MONTO, DATE_FORMAT(time,'%d/%m/%Y %T') AS FECHA, payed AS '1 PAG. / 0 PEND.' FROM $tabla ORDER BY payed DESC");
//
?>
Y así tengo un script por cada tabla... porque no logro "meter" todos en uno único... los "if" me desarman el payaso y no sale
![Stress](http://static.forosdelweb.com/fdwtheme/images/smilies/stress.png)
y es porque no sé cómo hacer para preguntar si existe un campo y según eso seguir un camino u otro.
Se entendió ?
Muchas gracias y saludos