Greeting all, and thanks to all for putting their time and effort into helping others solve their problems.
That being said, I’m currently one of the latter, and I’m seeking some help with PHP and XML.:queasy:
I have a website I’ve built for a non-profit agency that uses individual coupons written in XML along w/ DreamWeaver’s Spry Javascript to render the on a webpage.
While I’ve got it to a point that it’s not a nightmare to update weekly, it is not a efficient as it could be, so I’m wanting to upgrade the system a bit and use 1 XML document with all the coupons listed in it, and PHP w/ SimpleXML to parse it and output the coupons.
I’ve got that working just fine, but I need a few other capabilities that I think will require xPath, and I’m not sure how to make it happen.
So, take one coupon for example. The business name on the coupon needs to be a link that when clicked will open a new blank page with just that coupon on it for print purposes. This would be one method where the user can print off individual coupons if they like. So, when clicked, I think I would use xPath to identify the complete XML coupon/node, then take that info and using SimpleXML, create a new page on the fly w/ the coupon rendered in it. I can do this now w/ Spry, but it’s convoluted and I want to easy my updating burden.
Also, I want to make a checkbox on each coupon. The user can then check off coupons they like, then hit a submit button, and a page will be created on the fly for print that will have the coupons they chose displayed and ready to print. Same method as the single coupon above, just with multiple XML coupons/nodes passed to the page and SimpleXML rendering them.
My issue is with xPath. I’m not sure how to use it to target the exact XML node and port that info into it’s own document, if that makes sense.
Also, to make things worse, I need to be able to track the coupon. I think the easiest way for me to do this is assign the node number of the coupon as it’s title in the dynamic page, or create a spot for it’s node number to be in. Then, I can refer to a list of coupons, and for this week, I can see that coupon #3 was So&So’s and that coupon go 120 clicks. Something like that. Any suggestions on that would be very welcome.
So, to sum it all up, I need to figure out how to use xPath with the code below in order to get the coupon’s info from the list of coupon nodes, and distribute that info to another page that will either render that coupon, or mulitple ones.
Any and all help and advice would be greatly appreciated.
Thanks in advance!
Stymie
Here’s some sample code of what I have thus far:
XML Coupons:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<coupons>
<coupon id="1">
<expiration>Feb. 26, 2010</expiration>
<category>Fitness</category>
<company>Some Business</company>
<deal>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </deal>
<deal2>Nullam ut diam eget metus scelerisque pulvinar ut a ipsum. </deal2>
<deal3>Nullam ut sagittis justo. Praesent massa lacus, scelerisque sit amet mollis a, lobortis at dolor.</deal3>
<extra>Some Extra Info will go here if needed</extra>
<address>123 Some Street, Someplace, World, 12345</address>
<address2>123 Some Street, Someplace, World, 12345</address2>
<site>www.somewebsite.org</site>
<phone>123-123-1234</phone>
<legal>Not valid with any other offer or any other location.</legal>
</coupon>
<coupon id="2">
<expiration>March 26, 2010</expiration>
<category>Automotive</category>
<company>Whatchamacallits</company>
<deal>Suspendisse at lectus lectus, at blandit metus.</deal>
<deal2>Cras varius fermentum aliquet. Pellentesque habitant morbi tristique
<address>123 Some Street, Someplace, World, 12345</address>
<site>www.somewebsite.org</site>
<phone>123-123-1234</phone>
<legal>Not valid with any other offer or any other location.</legal>
</coupon>
<coupon id="3">
<expiration>April 26, 2010</expiration>
<category>Health</category>
<company>Jane Doe's</company>
<deal>Sed ullamcorper sodales luctus. Duis ut lacus at ante malesuada ultrices.</deal>
<extra>Some Extra Info will go here if needed</extra>
<address>123 Some Street, Someplace, World, 12345</address>
<site>www.somewebsite.org</site>
<phone>123-123-1234</phone>
<legal>Not valid with any other offer or any other location.</legal>
</coupon>
</coupons>
HTML w/ PHP using SimpleXML to render coupons:
<html>
<head>
<title>Coupons using XML & PHP</title>
<style type="text/css">
#coupon {
width:500px;
fontsize: 93.8%;
margin:0 0 1.5em;
padding:0.5em;
border: dotted 1px #000;
display: block;
list-style:none inside;
background-color:#fff!important;
}
#coupon h5 {width:100%;margin:0;padding:.5em 0;text-align:center;font-size: .75em;border:none; visibility:visible;color:#777;}
#coupon h4.float {float:right;font-size:.6em;margin: 1em 0 -.75em 1em;text-align:right;padding: 0.75em;background-color: #fff;border: none;color: #666;-webkit-border-radius: 1em;border:solid 1px #222;}
#coupon h4 {display:block;margin:0;padding:0;font-size:90%;border: none;}
#coupon h1 {display:block;margin:.25em 0 .5em;padding:.25em 0 .25em .75em;font-size:1.25em;font-family: 'Arial Black',Helvetica, Arial, sans-serif;color:#fff;font-weight: 900;border:solid 1px #000;-webkit-border-radius: 1em;-webkit-box-shadow: 0.3em 0.3em 0.3em #888; /* x,y,z coordinages (z is blur/depth) */
box-shadow: 0.3em 0.3em 0.3em #888;
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#444), to(#000));
}
#coupon h1 a {color:#336;font-weight: bold;}
#coupon h1 a:link {color:#ccc;}
#coupon h1 a:visited {color: #888;}
#coupon h1 a:hover {color: #fff;text-decoration:blink;}
#coupon h1 a:active {color:#900;}
#coupon h1#info {font-family: 'Arial Narrow',Helvetica,Arial,sans-serif;color:#fff;padding: .8em 1em;font-size:.8em;line-height:1.75;}
#coupon h2 {display:block;margin:0;padding:0 0 0 1em;font-size:100%;border:none;font-weight: normal;}
address {display:block;margin:0;padding:0;font-size:100%;text-align: center;border:none;}
#coupon h3 {display:block;margin:0;padding:0;font-size:95%;text-align: center;border:none;}
#coupon h6 {display:block;margin:0 auto;padding:0;font-size:85%;text-align: center;border:none;font-weight:light;}
</style>
</head>
<body>
<?php
if (file_exists('coupons.xml')) {
$coupons = simplexml_load_file('coupons.xml');
$CouponNumber = 1;#Defines the html coupons page starting at 1.
foreach($coupons->coupon as $coupon) {
$expiration = $coupon->expiration;
$category = $coupon->category;
$company = $coupon->company;
$deal = $coupon->deal;
$deal2 = $coupon->deal2;
$deal3 = $coupon->deal3;
$deal4 = $coupon->deal4;
$deal5 = $coupon->deal5;
$extra = $coupon->extra;
$address = $coupon->address;
$address2 = $coupon->address2;
$address3 = $coupon->address3;
$address4 = $coupon->address4;
$site = $coupon->site;
$phone = $coupon->phone;
$legal = $coupon->legal;
echo '<div id="coupon">
<input name="Select" type="checkbox" value="" />
<h4 class="float">'.$expiration.'</h4>
<h5>KingsportDeals.com | Click to Save, Click to Win!</h5>
<h4><'.$category.'</h4>
<h1><a href="coupon.php" target="_blank">'.$company.'</a></h1>
<h2>'.$deal.'</h2>
<h2>'.$deal2.'</h2>
<h2>'.$deal3.'</h2>
<h2>'.$deal4.'</h2>
<h2>'.$deal5.'</h2>
<h5>'.$extra.'</h5>
<address>'.$address.'</address>
<address>'.$address2.'</address>
<address>'.$address3.'</address>
<address>'.$address4.'</address>
<h3><a href="http: '.$site.' " target="_blank"> '.$site.' </a></h3>
<h5>'.$phone.'</h5>
<h6>'.$legal.'</h6>
</div>';
unset($expiration);
unset($category);
unset($company);
unset($deal);
unset($deal2);
unset($deal3);
unset($deal4);
unset($deal5);
unset($address);
unset($address2);
unset($address3);
unset($address4);
unset($site);
unset($legal);
$CouponNumber++; // increment by 1
}
}
?>
</body>
</html>