Hornicn Ierakstīts Oktobris 18, 2010 Share Ierakstīts Oktobris 18, 2010 Kods izskatās šādi. <?php $host = 'host'; $user = 'user'; $pass = 'pass'; $db = 'db'; $table = 'btable'; $file = 'export'; $query_variables = $_POST['id']; $link = mysql_connect($host, $user, $pass) or die("Can not connect to the host." . mysql_error()); mysql_select_db($db) or die("Can not connect to the particular database."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field']."; "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table." WHERE forwarded_oce='1'"); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j]."; "; $smallerid = $rowr[$i-1]; $smaller = mysql_query("SELECT budget FROM `db`.`table` WHERE id='$smallerid'"); } $csv_output .= $smaller; $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> problēma ir sekojoša. jau eksistējošai mysql datubāzes eksportam, katrai kolonnai ir jāpievieno papildus kolonna no citas datubāzes, kuras identifikātors ir jau eksistējošā eksporta pēdējā kolonnā esošs integer un var atšķirties katrai kolonnai. Vai kādam ir bijusi pieredze ar šāda veida eksportiem, un kā Jūs man ieteiktu šo ķibeli atrisināt? Oficiālajā PHP dokumentācijā neatradu noderīgus pavedienus kā apiet šo ķibeli. Pašlaik risinājums ir veikt 2 dažādus eksportus un pārējo izdarīt ar MACRO caur Ms Excel, bet tas ir laikietilpīgs process. Atrisināju, ceru ka kādam noderēs <?php $host = 'host'; $user = 'user'; $pass = 'pass'; $db = 'db'; $table = 'brochures_table'; $file = 'export'; $link = mysql_connect($host, $user, $pass) or die("Can not connect to the host." . mysql_error()); mysql_select_db($db) or die("Can not connect to the particular database."); $csv_output = ""; $last_col = ""; $values = mysql_query("SELECT * FROM ".$table." WHERE id='1'"); while ($rowr = mysql_fetch_assoc($values)) { if(!$csv_output){ foreach($rowr as $fld_name => $fld_val){ $csv_output .= $fld_name.", "; $last_col = $fld_name; } $csv_output .= "\n"; } $smallerid = $rowr[$last_col]; list($smaller) = mysql_fetch_row(mysql_query("SELECT budget FROM `db`.`table` WHERE id = '$smallerid'")); $rowr[] = $smaller; $csv_output .= implode(', ' , $rowr) ; $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Izveido kontu, vai pieraksties esošajā, lai komentētu
Jums ir jābūt šī foruma biedram, lai varētu komentēt tēmas
Izveidot jaunu kontu
Piereģistrējies un izveido jaunu kontu, tas būs viegli!
Reģistrēt jaunu kontuPierakstīties
Jums jau ir konts? Pierakstieties tajā šeit!
Pierakstīties tagad!