0
루프 내부 MySQL의 셀에서 변수를 만들기... 나는 제목이 질문의 내용에 대한 충분한 희망 PHP
나는에 MySQL 데이터베이스의 모든 행을 쓰는 다양한 소스에서 약간의 스크립트 함께 패치 한별도의 XML 파일. 그것은 그것이하기로되어있는 일을하지만, 나는 명명 규칙에 매달린다.
내보낼 행의 'id'열에서 XML 파일의 이름을 지정하고 싶습니다. 여기서 $id
은 파일 확장자의 이름입니다.
xpath를 통해 액세스를 시도했지만 아무 쓸모가 없습니다.
특정 열의 데이터 (셀)에 액세스하여 변수에 할당하려면 어떻게합니까?
<?php
$host = "";
$user = "";
$pass = "";
$database = "";
// Replace by a query that matches your database
$SQL_query = "SELECT * FROM data";
$DB_link = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $DB_link) or die ("Could not find or access the database.");
$result = mysql_query ($SQL_query, $DB_link) or die ("Data not found. Your SQL query didn't work... ");
//ROWS
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id;
$XML = "<?xml version=\"1.0\"?>\n";
$XML .= "<order>\n";
$XML .= "\t<item>\n";
$i = 0;
// cells
foreach ($row as $cell) {
// Escaping illegal characters - not tested actually ;)
$cell = str_replace("&", "&", $cell);
$cell = str_replace("<", "<", $cell);
$cell = str_replace(">", ">", $cell);
$cell = str_replace("\"", """, $cell);
$col_name = mysql_field_name($result,$i);
// creates the "<tag>contents</tag>" representing the column
$XML .= "\t\t<" . $col_name . ">" . $cell . "</" . $col_name . ">\n";
$i++;
}
$XML .= "\t</item>\n";
$XML .= "</order>\n";
$handle = fopen($id.'.xml','w+');
fwrite($handle,$XML);
fclose($handle);
}
?>
합니다. –
고마워요. 저는 XMLWriter를 사용하여 모든 것을 다시 빌드하고 작동 시켰습니다. –