สอบถามเรื่อง คำสั่ง Create Folder แล้วจะไป Select ข้อมูลจาก DB ขึ้นมาโชวแล้วสร้างไฟล์ ไฟล์ หนึ่ง ซึ่งอาจเปน text file แต่ใน text file จะมีข้อมูลที่ Query จาก DB มาโชว คะ
Code (PHP)
<?
$strSQL = "SELECT * FROM db";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$dir = "20140918";
$file_to_write = 'LICP2014091800601.LICP';
$content_to_write = "Generate LICP Success!!";
if( is_dir($dir) === false )
{
mkdir($dir);
}
$file = fopen($dir . '/' . $file_to_write,"w");
// a different way to write content into
// fwrite($file,"Hello World.");
fwrite($file, $content_to_write);
// closes the file
fclose($file);
// this will show the created file from the created folder on screen
include $dir . '/' . $file_to_write;
?>
<?php
$dir = "20140918";
$file_to_write = 'LICP2014091800601.LICP';
$content_to_write = "$objWrite";
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("dea");
$strSQL = "SELECT * FROM dea";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
fwrite($objWrite, "\"$objResult[no]\",\"$objResult[passport]\",\"$objResult[yodeng]\",");
fwrite($objWrite, "\"$objResult[nameeng]\",\"$objResult[lastnameeng]\",\"$objResult[yod]\" \r\n");
}
if( is_dir($dir) === false )
{
mkdir($dir);
}
$file = fopen($dir . '/' . $file_to_write,"w");
// a different way to write content into
// fwrite($file,"Hello World.");
fwrite($file, $content_to_write);
// closes the file
fclose($file);
// this will show the created file from the created folder on screen
include $dir . '/' . $file_to_write;
?>