0

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.

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:

<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.

3
  • The XML feed is refreshed only the page get refreshed. In what case you want this auto refresh feature? because whenever you access the link for this xml feed, it will produce with the updated data. So explain what situation you need this feature? Commented Oct 26, 2012 at 5:30
  • am a android developed.here i have to use xml parsing.so i have to develop xml feed from mysql database using php code.here if i have to change the data on mysql database means its automatically update on my xml feed.then only update data is display on android mobile.otherwise its display previous xml feed datas only. Commented Oct 26, 2012 at 5:41
  • yes. So whenever you access for the xml feed link, it will give you the updated data only. for this, you no need to save this as a file. just set the xml header in the php page and access it directly. Commented Oct 26, 2012 at 5:43

2 Answers 2

1

Try like this: 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:

http://www.exampleyourdoamin/feed.php

Sign up to request clarification or add additional context in comments.

4 Comments

i wish to run the xml feed have xml link only.here shouldn't use php link.exampleyourdoamin/feed.xml only.shouldn't use exampleyourdoamin/feed.php
when you use feed.xml, it is a static file, so every time you need to create this file using cron jobs. otherwise you can't create these files automatically. instead you can create this as feed.php and set the header as XML, and call as usual and will work fine.
how can i create this as feed.php and set the header as XML.give me some coding part.because i can't understand.am a beginner in php
I have written the code for creating the xml feed above. create a file feed.php and put the above code in that file and run it in the browser. provide the same URL in the android app to access this feed.. the only thing you have to do is dont save the feed as static XML file.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.