简体   繁体   English

自动从mysql db更新xml feed,而无需刷新页面

[英]automatically update xml feed from mysql db without refresh the page

I have to develop one xml feed from mysql database using php code..here i have to insert or update any data on my mysql database means that inserted and updated data automatically change and insert on my xml feed also without refresh the page.how can i develop this.please help me. 我必须使用php代码从mysql数据库开发一个xml提要。在这里,我必须在mysql数据库中插入或更新任何数据,这意味着插入和更新的数据会自动更改并插入到xml提要中,而无需刷新页面。我发展这个。请帮助我。

i have used below code: 我用下面的代码:

$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;
     ?>

Now i got the below xml feed: 现在我得到了下面的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>

Now i wish to change the total 399.99 to 500.00 for orderid=1 on my mysql database means have to refresh the page.then only my xml feed is changed here.but i wish to need the solution is the database change is automatically update on my xml feed without refresh the page.please help me.how can i develop this. 现在我想将我的mysql数据库上的orderid = 1的总数从399.99更改为500.00,这意味着必须刷新页面。然后,这里只更改了我的xml feed。但是我希望解决方案是数据库更改会自动更新xml提要,但不刷新页面。请帮助我。我该如何开发它。

Try like this: feed.php 尝试这样: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;

in the XML feed URL access like this: 在XML feed URL访问中,如下所示:

http://www.exampleyourdoamin/feed.php http://www.exampleyourdoamin/feed.php

You need to use a technique called long polling. 您需要使用一种称为长轮询的技术。 Long polling keeps a connection open for certain amount of time. 长轮询使连接在一定时间内保持打开状态。 During this time it checks if there is any change in database. 在此期间,它将检查数据库中是否有任何更改。 If yes, it breaks the connection and sends those changes to frontend. 如果是,它将断开连接并将这些更改发送到前端。 And then immediately starts another connection. 然后立即启动另一个连接。 You will find more information here. 您将在此处找到更多信息。 http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery

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

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