php
  • mysql
  • xml
  • 2012-10-26 63 views 0 likes 
    0

    我必须从MySQL数据库开发一个XML提要使用PHP代码..我必须插入或更新我的MySQL数据库上的任何数据意味着插入和更新的数据自动更改并插入我的xml饲料也无需刷新页面。我可以开发this.please帮助我。自动更新从MySQL数据库的XML饲料,而无需刷新页面

    我用下面的代码:

    $catname=func_query_first_cell("select status from $sql_tbl[orders] where status='Q'"); 
        $file= fopen("orderdetails1.xml", "w");   
        $_xml ="<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\r\n"; 
        $_xml .="\t<Feed>\r\n"; 
        $_xml .="\t<order>\r\n"; 
    
    $_xml .="\t<status>" .htmlspecialchars($catname,ENT_QUOTES). "</status>\r\n"; 
    $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]); 
    $limit = 2; 
    $startpoint = ($page * $limit) - $limit; 
    $statement = "`xcart_orders` where `active` = 1";  
    $counterr=0; 
    $r=func_query("select * from $sql_tbl[orders] LIMIT {$startpoint}, {$limit}"); 
    foreach($r as $n) 
    { 
    $products=func_query_first("select * from $sql_tbl[orders] where status='Q'"); 
    $products=func_query_first("select product from $sql_tbl[order_details] where orderid=$n[orderid]"); 
    
    $infeed_counter++; 
    
    echo $manufacturer."====="; 
    
    if($row[avail]>0) 
           $avail='Y'; 
          else 
           $avail='N'; 
    
    
    $_xml .="\t<Order>\r\n"; 
        $_xml .="\t<orderid>" .$n[orderid]. "</orderid>\r\n"; 
        $_xml .="\t<login>" . htmlspecialchars(strip_tags(substr($n[login],0,50)) , ENT_QUOTES). "</login>\r\n"; 
    $_xml .="\t<total>" . $n[total]. "</total>\r\n"; 
        $_xml .="\t<product>" . $products[product]. "</product>\r\n"; 
        $_xml .="\t</Order>\r\n"; 
    } 
    
        $_xml .="\t</order>\r\n"; 
        $_xml .="\t</Feed>\r\n";  
    fwrite($file, $_xml);  
    fclose($file);  
    echo "XML version of products available here with $infeed_counter products. <a href=\"orderdetails1.xml?page=$page\">View the XML.</a>"; 
        exit; 
        ?> 
    

    现在,我得到下面的XML提要:

    <Feed> 
    <order> 
    <status>Q</status> 
    <Order> 
        <orderid>1</orderid> 
         <login>krishna</login> 
         <total>399.99</total> 
         <product>Designing Web Usability</product> 
    </Order> 
    <Order> 
         <orderid>65</orderid> 
         <login>krishna</login> 
         <total>399.99</total> 
         <product>Three Stone Princess Cut Diamond Ring</product> 
        </Order> 
    <Order> 
          <orderid>2</orderid> 
          <login>krishna</login> 
          <total>34.65</total> 
          <product>Three Stone Princess Cut Diamond Ring</product> 
    </Order> 
    

    现在我想总的399.99更改为500.00订单id = 1我的MySQL数据库意味着必须刷新page.then只有我的xml饲料在这里改变。但我希望需要的解决方案是数据库更改是自动更新我的xml饲料而不刷新页面。请帮助我。我可以开发这个。

    +0

    的XML饲料只刷新页面获取刷新。在什么情况下你想要这个自动刷新功能?因为无论何时访问此XML feed的链接,它都会生成更新后的数据。那么说明你需要这种功能的情况? –

    +0

    是一个android开发的。我必须使用xml parsing.so我必须使用php code.here来开发来自mysql数据库的xml feed如果我必须更改mysql数据库上的数据意味着它会自动更新我的xml feed.then更新数据显示在android mobile.otherwise它显示以前的XML feed数据只。 – user1676640

    +0

    是的。因此,无论何时访问xml供稿链接,它只会为您提供更新的数据。为此,您不需要将其另存为文件。只需在PHP页面中设置xml标题并直接访问它。 –

    回答

    1

    尝试这样的: feed.php

    $catname = func_query_first_cell("select status from $sql_tbl[orders] where status='Q'"); 
    $file = fopen("orderdetails1.xml", "w"); 
    $_xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>"; 
    $_xml .= "<Feed>"; 
    $_xml .= "<order>"; 
    
    $_xml .= "<status>" . htmlspecialchars($catname, ENT_QUOTES) . "</status>"; 
    $page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]); 
    $limit = 2; 
    $startpoint = ($page * $limit) - $limit; 
    $statement = "`xcart_orders` where `active` = 1"; 
    $counterr = 0; 
    $r = func_query("select * from $sql_tbl[orders] LIMIT {$startpoint}, {$limit}"); 
    foreach ($r as $n) 
    { 
        $products = func_query_first("select * from $sql_tbl[orders] where status='Q'"); 
        $products = func_query_first("select product from $sql_tbl[order_details] where orderid=$n[orderid]"); 
    
        $infeed_counter++; 
    
        // echo $manufacturer."====="; 
    
        if ($row[avail] > 0) 
         $avail = 'Y'; 
        else 
         $avail = 'N'; 
    
    
        $_xml .= "<Order>"; 
        $_xml .= "<orderid>" . $n[orderid] . "</orderid>"; 
        $_xml .= "<login>" . htmlspecialchars(strip_tags(substr($n[login], 0, 50)), ENT_QUOTES) . "</login>"; 
        $_xml .= "<total>" . $n[total] . "</total>"; 
        $_xml .= "<product>" . $products[product] . "</product>"; 
        $_xml .= "</Order>"; 
    } 
    
    $_xml .= "</order>"; 
    $_xml .= "</Feed>"; 
    
    header ("Content-Type:text/xml"); 
    echo $_xml; 
    
    在这样的XML提要URL访问

    http://www.exampleyourdoamin/feed.php

    +0

    我希望运行xml提要只有xml链接。不应该使用php链接.http://www.exampleyourdoamin/feed.xml only.shouldn't使用http://www.exampleyourdoamin/feed.php – user1676640

    +0

    当您使用feed.xml时,它是一个静态文件,所以每次需要使用cron作业创建该文件时。否则你不能自动创建这些文件。相反,你可以创建这个feed.php并设置标题为XML,并像往常一样调用,并会正常工作。 –

    +0

    我怎样才能创建这个feed.php并设置标题为XML.give我一些编码部分。因为我不明白。我是一个初学者在php – user1676640

    0

    您需要使用称为长轮询的技术。长时间轮询会使连接保持打开一段时间。在此期间,它会检查数据库中是否有任何更改。如果是,它会中断连接并将这些更改发送到前端。然后立即开始另一个连接。你会在这里找到更多的信息。 http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery

    相关问题