I don't know PHP very well because I am android developer so please help me. I have just trying to enter XML data into database using PHP. I have see other examples but don't get what can I do in my case.
XML link : http://ca.sharmatutorial.com/ws.asmx/GET_Question_ByDate?dtDate=2016-03-17
PHP Code: Here what can I define for retrieve and set data in database. I know below code not correct. please correct my for each loop for opt object and other also please check my sql query.
<!doctype HTML>
<html>
<head>
<?php
header('Content-Type: application/xml; charset=utf-8');
$mysqli = new mysqli ( 'localhost', 'mabhim92', '9993115300', 'gcm_chat');
?>
</head>
<body>
<?php
$xml = simplexml_load_file("http://ca.sharmatutorial.com/ws.asmx/GET_Question_ByDate?dtDate=2016-03-17");
$nodes = new SimpleXMLElement($xml, null, true)
or die("cannot create");
foreach ($nodes->children() as $child)
{
$Ques_id= $child->id;
$Question= $child->text;
$Option_1= $child->opt;
$Option_2= $child->opt;
$Option_3= $child->opt;
$Option_4= $child->opt;
$Answer= $child->opt->ans;
$date= $child->date;
));
$sql = "INSERT INTO feeds (Ques_id, Question, Option_1, Option_2, Option_3, Option_4, Answer, date) VALUES('". $Ques_id."','". $Question."','". $Option_1."','". $Option_2."','". $Option_3."','". $Option_4."','". $Answer."','". $date."')";
mysql_query($sql);
}
?>
</body>
</html>
My database field:
1 Ques_id = id
2 Question = text
3 Option_1 = opt (first obj in opts value)
4 Option_2 = opt (second obj in opts value)
5 Option_3 = opt (third obj in opts value)
6 Option_4 = opt (fourth obj in opts value)
7 Answer = (which opt is ans=1)
8 date (timestamp) = date