0

i want to send xml response. I tried following code. but does not print array element but only print "array". Please tell me where i am wrong?

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("video_link");

    try {   
        $query = "select * from upload_video";
        $result = mysql_query($query);

    }
    catch(Exception $ex) {

        $response = '<?xml version="1.0" encoding="utf-8"?>';
            $response .= '<response><status>'.'0'.'</status>';
        $response = $response.'<remarks>'.'Error'.'</remarks></response>';
        header("Content-type: text/xml; charset=utf-8");
        echo $response;
    }

    $n = mysql_num_rows($result);

    for($i=0; $i < $n; $i++) {
        $url = mysql_result($result,$i,'url');

        $store[] = array("url" => $url);     

            }

            $response = '<?xml version="1.0" encoding="utf-8"?>';
            $response .= '<response><status>'.'1'.'</status>';
        $response = $response.'<remarks>'.$store.'</remarks></response>';
        header("Content-type: text/xml; charset=utf-8");
        echo $response;

?>
Sergiu Paraschiv
  • 9,929
  • 5
  • 36
  • 47
user2809576
  • 121
  • 1
  • 2
  • 11

1 Answers1

0

Use this to write the XML as you see fit instead of your for loop if you want the list items as XML nodes :

$list = "";
for($i=0; $i < $n; $i++) {
    $url = mysql_result($result,$i,'url');
    $list .= "<item>".$url."</item>";
 }

Or simply use implode on your $store array if a comma seperated list is enough:

$response = $response.'<remarks>'.implode(", ", $store).'</remarks></response>';
ToBe
  • 2,667
  • 1
  • 18
  • 30