Veikia puikiai bet ignoruoja eilutes kur kode yra raide pvz "StoItem
Code="1011000A".
Code gali but ir vien raides. Kur cia pataisyt?
"scrp" wrote in message news:kl80n2$l5d$1@trimpas.omnitel.net...
kaip tokiam paprastam xml'ui tai daryciau paprasciau:
preg_match_all("|<StoItem Code=\"(\d+)\" QtyFree=\"(\d+)\" />|m",
file_get_contents("test.xml"), $r);
$n=count($r[0]);
while($n-->0) { echo "insert into table code='{$r[1][$n]}',
qty='{$r[2][$n]}';<br />"; }
"VaidasB" wrote in message news:kl7ucv$im9$1@trimpas.omnitel.net...
$doc = new DomDocument();
$doc->loadXML($xml));
$nodeList = $doc->getElementsByTagName('StoItem');
foreach ($nodeList as $node)
{
$code = $node->getAttribute('Code');
$count = $node->getAttribute('QtyFree');
$sql = "INSERT INTO MYSQLLENTELE(code, qty) VALUES('$code', '$count')";
$dbh->execute($sql);//čia jau pats turi pasidaryt
}
jei nepalaiko domDocument,
tada žaidi su
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $xml, $vals, $index);
xml_parser_free($parser);
ir suki foreach per $vals ir ten ieškai pažįstamų reikšmių
On 2013.04.23 17:16, Vinetu wrote:
> Pagelbekit. Reikia PHP pagalba XML perkelti i tuscia MySQL lentele
> kurioje du stulpeliai "code" ir "qty".
>
> XML atrodo taip:
>
> <Result>
> <StoItem Code="10110001" QtyFree="17" />
> <StoItem Code="10110002" QtyFree="17" />
> <StoItem Code="10110003" QtyFree="24" />
> <StoItem Code="10110004" QtyFree="27" />
> <StoItem Code="10110005" QtyFree="12" />
> <StoItem Code="10110006" QtyFree="20" />
> </Result>
>
>