Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve Selected Records With Xpath
    primarykey
    data
    text
    <p>I wonder whether someone may be able to help me please.</p> <p>I'm using the script below to create a 'gallery' page. </p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;?php //This variable specifies relative path to the folder, where the gallery with uploaded files is located. $galleryPath = 'UploadedFiles/'; $thumbnailsPath = $galleryPath . 'Thumbnails/'; $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; $descriptions = new DOMDocument('1.0'); $descriptions-&gt;load($absGalleryPath . 'files.xml'); path="files[userid=1]/originalname/folder/description/source/thumbnail"; // code for IE if (window.ActiveXObject) { var nodes=xml.selectNodes(path); for (i=0;i&lt;nodes.length;i++) { document.write(nodes[i].childNodes[0].nodeValue); } } ?&gt; &lt;head&gt; &lt;title&gt;Gallery&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="Styles/style.css" rel="stylesheet" type="text/css" /&gt; &lt;!--[if IE]&gt; &lt;link href="Styles/ie.css" rel="stylesheet" type="text/css" /&gt; &lt;![endif]--&gt; &lt;script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function() { $('a.fancybox').fancybox(); }); &lt;/script&gt; &lt;style type="text/css"&gt; &lt;!-- .style1 { font-size: 14px; margin-right: 110px; } .style4 {font-size: 12px} --&gt; &lt;/style&gt; &lt;/head&gt; &lt;body style="font-family: Calibri; color: #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -475px; margin-right: 1px; margin-bottom: -10px;"&gt; &lt;div align="right" class="style1"&gt; &lt;a href = "imagefolders.php" /&gt; View Uploaded Images In Folder Structure &lt;a/&gt; &amp;larr; View All Uploaded Images &lt;/div&gt; &lt;form id="gallery" class="page"&gt; &lt;div id="container"&gt; &lt;div id="center"&gt; &lt;div class="aB"&gt; &lt;div class="aB-B"&gt; &lt;?php if ('Uploaded files' != $current['title']) :?&gt; &lt;?php endif;?&gt; &lt;label&gt; &lt;input name="userid" type="text" id="userid" value="1" /&gt; &lt;input name="locationid" type="text" id="locationid" value="1" /&gt; &lt;/label&gt; &lt;div class="demo"&gt; &lt;div class="inner"&gt; &lt;div class="container"&gt; &lt;div class="gallery"&gt; &lt;ul class="gallery-image-list"&gt; &lt;?php for ($i = 0; $i &lt; $descriptions-&gt;documentElement-&gt;childNodes-&gt;length; $i++) : $xmlFile = $descriptions-&gt;documentElement-&gt;childNodes-&gt;item($i); $name = htmlentities($xmlFile-&gt;getAttribute('originalname'), ENT_COMPAT, 'UTF-8'); $description = htmlentities($xmlFile-&gt;getAttribute('description'), ENT_COMPAT, 'UTF-8'); $folder = htmlentities($xmlFile-&gt;getAttribute('folder'), ENT_COMPAT, 'UTF-8'); $source = $galleryPath . rawurlencode($xmlFile-&gt;getAttribute('source')); $thumbnail = $thumbnailsPath . rawurlencode($xmlFile-&gt;getAttribute('thumbnail')); ?&gt; &lt;li class="item"&gt; &lt;a class="fancybox" target="_blank" rel="original" href="&lt;?php echo $source; ?&gt;"&gt;&lt;img class="preview" alt="&lt;?php echo $name; ?&gt;" src="&lt;?php echo $thumbnail; ?&gt;" /&gt;&lt;/a&gt; &lt;/li&gt; &lt;li class="item"&gt;&lt;/li&gt; &lt;p&gt;&lt;span class="style4"&gt;&lt;b&gt;Image Description:&lt;/b&gt; &lt;?php echo htmlentities($xmlFile-&gt;getAttribute('description'));?&gt; &lt;br /&gt; &lt;b&gt;Image contained in folder:&lt;/b&gt; &lt;?php echo htmlentities($xmlFile-&gt;getAttribute('folder'));?&gt; &lt;/span&gt;&lt;br /&gt; &lt;?php endfor; ?&gt; &lt;/li&gt; &lt;/p&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="aB-a"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The data for this page comes from the file, 'files.xml', an extract of which can be found below.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; - &lt;files&gt; &lt;file name="Test 1/article-0-07D01B74000005DC-138_468x617.jpg" source="article-0-07D01B74000005DC-138_468x617.jpg" size="143110" originalname="article-0-07D01B74000005DC-138_468x617.jpg" thumbnail="article-0-07D01B74000005DC-138_468x617.jpg" description="No description provided" userid="1" locationid="1" folder="Test_1" /&gt; &lt;/files&gt; </code></pre> <p>What I wanted to do is filter the records returned, to be more specific by 'userid' and 'locationid' and for testing purposes these had the value of '1'.</p> <p>I'd received some useful guidance from this site at <a href="https://stackoverflow.com/questions/9749774/xml-select-where-statement">XML &#39;Select Where&#39; Statement</a>, and from the subsequent 'XPath' tutorials I've read I put together what I thought would be the correct xpath code to use which is at the top of my 'gallery' page script.</p> <p>However, when I've tried to run this I recieve the following error:</p> <p><code>Parse error: syntax error, unexpected '=' in /homepages/2/d333603417/htdocs/development/gallery.php on line 16</code></p> <p>It's clear that the problem is with the 'equals', but when I've gone back to the tutorials, this appears to be the correct syntax to use.</p> <p>I just wondered whether someone could perhaps have a look at this please and let me know where I've gone wrong.</p> <p>Many thanks</p> <p><strong>Amended Xpath Code</strong></p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;?php $galleryPath = 'UploadedFiles/'; $thumbnailsPath = $galleryPath . 'Thumbnails/'; $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; $descriptions = new DOMDocument('1.0'); $descriptions-&gt;load($absGalleryPath . 'files.xml'); /files/file[@userid="1" and @locationid="1"]; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload