Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPhilip G
14,600 PointsSum SimpleXML XPath variable doesn't work
Hi Community,
For a friend of mine, I'm creating a PDF-View-Counter. Now I'm getting stuck at changing the "view" value from the XML. When I'm trying to sum the variable ($VAR++), doesn't work. What should I do?
PHP-Code:
<?php
//header('Content-type: application/pdf');
// PDF-Datei deklarieren
$datei = "pdf.pdf";
$xmldb = "db.xml";
$id = md5($datei);
$xml = simplexml_load_file($xmldb);
$views = $xml->xpath('/data/count[@id="'.$id.'"]/views');
$num = $views[0][0];
$num++;
echo $num;
//$fopen = fopen($xmldb, "wb");
//fwrite($fopen, $xml->asXML());
//fclose($fopen);
//readfile($datei);
?>
XML-Code:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<count id="883c7046854e04138c55680ffde90a61">
<filename>s</filename>
<views>1</views>
<lastview>f</lastview>
</count>
</data>
PS: I now that the Code is dirty but it was made in hurry.
Many thanks in advance,
Philip