mysql730.db.sakura.ne.jpです:最初のページに戻る ?php> //******************************************************************************** //t_shisanhyouからデータ検索 //******************************************************************************** $tablename="t_shisanhyou"; $sql = "SELECT * FROM ".$tablename; // $sql = $sql." WHERE ".$sql3; //echo $sql; $data=$p_class->select_num($sql); $resultNum=count($data); echo '
'.$tablename.$resultNum.'件見つかりました'; /* $data[$i][0];///ID $data[$i][1];///簿記CD $data[$i][2];///借方残高 $data[$i][3];///貸方残高 $data[$i][4];///借方累計残高 $data[$i][5];///借方当月残高 $data[$i][6];///貸方累計残高 $data[$i][7];///貸方当月残高 $data[$i][8];///借方期首残高 $data[$i][9];///貸方期首残高 $data[$i][10];//勘定略称 */ //CSV文字列生成(フィールド名) $csvstr = ""; $csvstr .= "ID" . ","; $csvstr .= "簿記CD" . ","; $csvstr .= "借方残高" . ","; $csvstr .= "貸方残高" . ","; $csvstr .= "借方累計残高" . ","; $csvstr .= "借方当月残高" . ","; $csvstr .= "貸方累計残高" . ","; $csvstr .= "貸方当月残高" . ","; $csvstr .= "借方期首残高" . ","; $csvstr .= "貸方期首残高" . ","; $csvstr .= "勘定略称" . "\r\n"; //CSV文字列生成(レコード) for($i=0;$i<$resultNum;$i++) { $csvstr .= $data[$i][0] . ","; $csvstr .= $data[$i][1] . ","; $csvstr .= $data[$i][2] . ","; $csvstr .= $data[$i][3] . ","; $csvstr .= $data[$i][4] . ","; $csvstr .= $data[$i][5] . ","; $csvstr .= $data[$i][6] . ","; $csvstr .= $data[$i][7] . ","; $csvstr .= $data[$i][8] . ","; $csvstr .= $data[$i][9] . ","; $csvstr .= $data[$i][10] . "\r\n"; } //CSV出力ファイル名の設定 // $fileNm = $data[0][0]."-houjin.csv"; $fileNm = "shisanhyou.csv"; //出力バッファのクリア:headder関数の前に必須 ob_clean(); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename='.$fileNm); echo mb_convert_encoding($csvstr, "SJIS", "UTF-8"); //Shift-JISに変換したい場合のみ exit(); /* }catch(ErrorException $ex){ print('ErrorException:' . $ex->getMessage()); }catch(PDOException $ex){ print('PDOException:' . $ex->getMessage()); } } */ ?>