php - How to retrieve data from MySQL database and save it to xml file -
need im badly stuck here. have mysql database , html form.i can connect database through form without problem. buttons (find, delete, update , add) work perfectly.now decided add print button suppose export retrieved data xml file(that converted pdf file later know how deal that). idea how or start??? there php function can use?
i resolved issue creating function print button , calling function later. working perfectly.
function printrecords($query){ global $id, $name, $address,$country, $ph_number; $result = mysql_query($query); $resultcount = mysql_num_rows($result); $query= 'select id, name, address , country, ph_number people'; $fp= @fopen ("somefile.xml","w")or die ("could not open file"); $data = ""; ($r=0; $r<$resultcount; $r++) { $rec = mysql_fetch_assoc($result); $data = sprintf("<name>%s</name>\r\n<address>%s</address>\r\n <ph_number>%s</ph_number>\r\n" $rec['name'], $rec['address'], $rec['ph_number'] ); fwrite($fp, $data); } @fclose($fp); return($resultcount); }
tried xml export via mysql command line ?
e.g.
mysql -uroot -p --xml -e 'select * mydb.table1' > table1.xml
see mysql manual command options xml
and saw have access database thru html form, , maybe can't run command line?
otherwise own xmldoc select, simple query made here sqlfiddle.
create table animal(id int, name char(10)); insert animal values (1,'dog'), (2,'cat'), (3,'mouse'), (4,'horse'), (5,'cow'); select concat('\n<animals>\n', group_concat('<animal id=', id, '>',name,'</animal>\n' separator ''), '</animals>') xmldoc animal; output be:
<animals> <animal id=1>dog</animal> <animal id=2>cat</animal> <animal id=3>mouse</animal> <animal id=4>horse</animal> <animal id=5>cow</animal> </animals>
Comments
Post a Comment