简体   繁体   English

如何在xml中存储数据?

[英]How to store data in xml?

I have one php file in which i am displaying data of xml file by this code 我有一个php文件,其中我通过此代码显示xml文件的数据

<?php
    $xml = simplexml_load_file("note.xml") or die("Error: Cannot create object");
    foreach($xml->xpath('//agent') as $item) { 
    $row = simplexml_load_string($item->asXML());
    $v = $row->xpath('//id[. ="1"]');
    if($v[0]){ 
        print $item->id; 
        print $item->image; 
        print $item->name; 
        print $item->company; 
        print $item->street; 
        print $item->city;
        print $item->phone; 
    }
    else{
        echo 'No records';
    }
?>

Now i want to store this displayed data into other pages of my site and i am begginer of php so not expert in session. 现在,我想将显示的数据存储到我网站的其他页面中,我是php的初学者,因此不是会话专家。

and i want to store this detail in session for displaying this data into other pages of my site. 我想在会话中存储此详细信息,以便将这些数据显示到我网站的其他页面中。 for storing this data into session i have tried this code on same page 用于将数据存储到会话中,我已经在同一页面上尝试过此代码

<?php
session_start();
$name = $_session_['$item->name'];
?>

But thats not help, So please guys can you suggest me where i am wrong. 但这并没有帮助,所以请大家向我建议我错了。

any suggestion should be appreciable. 任何建议都应该是可理解的。

Start ur session in first doc. 在第一个文档中启动您的会话。

<?php
    session_start();

    $xml = simplexml_load_file("note.xml") or die("Error: Cannot create object");
    foreach($xml->xpath('//agent') as $item) { 
    $row = simplexml_load_string($item->asXML());
    $v = $row->xpath('//id[. ="1"]');
    if($v[0]){ 
        print $item->id; 
        print $item->image; 
        print $item->name; 
        print $item->company; 
        print $item->street; 
        print $item->city;
        print $item->phone; 
    }
    else{
        echo 'No records';
    }

   $name = $_session['name'][$item->name]; // dont quote ''
?>

http://www.w3schools.com/php/php_sessions.asp http://www.w3schools.com/php/php_sessions.asp

your session code is not valid, you may try this one ; 您的会话代码无效,您可以尝试使用此代码;

$name = $_session['name'][$item->name]; $ name = $ _session ['name'] [$ item-> name];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM