-1

我的 php 代码在下面,它产生的源代码为我提供了我想要保存为 xml 文件的数据。我怎么能这样做?

ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();
include_once('function.php');

$select_query = build_select_query("xml","cust_id",$_SESSION['cust_id']);
$query = mysqli_query($link,$select_query);
$num_rows = mysqli_num_rows($query);
    if($num_rows > 0){
        while($row = mysqli_fetch_assoc($query)){
?>
<all>
    <Phonebooks>
        <book id='{$row['bookid']}' Bookid='{$row['bookid']}' speedid='{$row['speedid']}' accountid='{$row['accountid']}'
        GroupName='{$row['groupid']}' FirstName='{$row['firstname']}' Username='{$row['username']}'
        MobileNum='{$row['mobilenum']}' OfficeNum='{$row['officenum']}' OtherNum='{$row['othernum']}' NewVer='{$row['newver']}' ISUseBLF='{$row['isuseblf']}'
        LastName='{$row['lastname']}' GroupNameTwo='{$row['groupnametwo']}' />

    </Phonebooks>
</all>
<?php
        }
    }





?>
4

1 回答 1

1

请尽量让您的问题在未来尽可能清晰。这样你就可以马上得到正确的答案。

make_my_xml.php - 当您在浏览器中将其加载为 stuff.xml 时,此文件会打印 xml 并保存/下载

<?php  
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');

    // change this line to change the filename it saves as
    header('Content-Disposition: attachment; filename=stuff.xml');

    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public'); 

    // your code goes here 

    ini_set ("display_errors", "1");
    error_reporting(E_ALL);
    session_start();
    include_once('function.php'); 

    $select_query = build_select_query("xml","cust_id",$_SESSION['cust_id']);
    $query = mysqli_query($link,$select_query);
    $num_rows = mysqli_num_rows($query);
    if($num_rows > 0){
        while($row = mysqli_fetch_assoc($query)){
   ?>
   <all>
       <Phonebooks>
           <book id='{$row['bookid']}' Bookid='{$row['bookid']}' speedid='{$row['speedid']}' accountid='{$row['accountid']}'
           GroupName='{$row['groupid']}' FirstName='{$row['firstname']}' Username='{$row['username']}'
           MobileNum='{$row['mobilenum']}' OfficeNum='{$row['officenum']}' OtherNum='{$row['othernum']}' NewVer='{$row['newver']}' ISUseBLF='{$row['isuseblf']}'
           LastName='{$row['lastname']}' GroupNameTwo='{$row['groupnametwo']}' /> 
       </Phonebooks>
    </all>
    <?php
        }
    }  
    ?>

如果您想通过单击按钮来执行此操作...我想,只需制作一个普通按钮或链接,该按钮或链接将转到包含创建/保存 xml 文件的代码的页面。我错过了什么吗?

other_file.php - 链接到页面的两种不同方式

<a href="make_my_xml.php" target="_blank">Click here to download an xml file!</a>

<form method="link" action="make_my_xml.php"><input type="submit" value="Click to Download XML File"></form>

请告诉我此解决方案是否适合您....

于 2013-11-05T23:28:34.230 回答