while i'm sure there are some better ways to do this, for the sake of what i thought would have been simplicity i just want to use an existing php/xml setup to display rotating banners and images.
well, when i go to drop it all in there i get a smarty error, and i have no idea how the heck to fix this.
i will post all code in case anyone wants to use something like this.
so, to start...
this is the main php. it was in the head of the old pages, but it could go in it's own php file correct?
Code:
<?php
#
# $Id: slideshow.php,v 1.30.2.5 2007/03/22 13:54:22 svowl Exp $
#
$depth = array();
function startElement($parser, $name, $attrs) {
global $depth;
global $slides, $feature, $banners;
if ($name=='SLIDE') { $slides[] = $attrs; }
if ($name=='FEATURE') { $feature[] = $attrs; }
if ($name=='BANNER') { $banners[] = $attrs; }
$depth[$parser]++;
}
function endElement($parser, $name) {
global $depth;
$depth[$parser]--;
}
function readXML($file) {
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) { die("could not open XML input"); }
while ($data = fread($fp, 4096)) {
xml_parse($xml_parser, str_replace('&','&',$data), feof($fp));
/*if (!xml_parse($xml_parser, $data, feof($fp))) {
die (sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}*/
}
xml_parser_free($xml_parser);
}
####
readXML("features.xml");
$nums = array_rand($feature,3);
foreach($nums as $k => $i) {
$v = $feature[$i];
print " <td width=\"164\" align=\"center\">\n";
print " <a href = \"{$v['HREF']}\"><img src=\"{$v['SRC']}\" alt=\"{$v['TITLE']}\" border=\"0\" height=\"125\" width=\"125\"></a><br>\n";
print " <a href = \"{$v['HREF']}\"><font face=\"arial\" size=\"2\">{$v['TITLE']}</font></a>\n";
print " </td>\n";
}
?>
then, in the page itself, you have the elements to display our rotating banner ads/slideshow...
Code:
<?
readXML("banners.xml");
$nums = array_rand($banners,2);
foreach($nums as $k => $i) {
$v = $banners[$i];
print " <p><a href = \"{$v['HREF']}\"><img src=\"{$v['SRC']}\" alt=\"{$v['TITLE']}\" border=\"0\"></a></p>\n";
}
?>
</td>
<?
readXML("features.xml");
$nums = array_rand($feature,3);
foreach($nums as $k => $i) {
$v = $feature[$i];
print " <td width=\"164\" align=\"center\">\n";
print " <a href = \"{$v['HREF']}\"><img src=\"{$v['SRC']}\" alt=\"{$v['TITLE']}\" border=\"0\" height=\"125\" width=\"125\"></a><br>\n";
print " <a href = \"{$v['HREF']}\"><font face=\"arial\" size=\"2\">{$v['TITLE']}</font></a>\n";
print " </td>\n";
}
?>
lastly, add all the images into an XML file names banners.xml or features.xml which contains this...
<banners>
<banner src="images/banner_2.jpg">
<banner src="images/banner_24.gif">
<banner src="images/banner_25.gif" href="IF YOU WANT TO LINK" />
<banner src="images/banner_26.gif">
<banner src="images/banner_27.gif">
</banners>
<features>
<feature src="images/image.jpg" href="link" title="title"/>
<feature src="images/image.jpg" href="link" title="title"/>
</features>
questions....
when i embed the code into the page, do you embed it with the <? and ?> ?
why am i getting this error?
Error: Smarty error: [in today_news.tpl line 22]: syntax error: unrecognized tag: $v['SRC'] (Smarty_Compiler.class.php, line 436) in
/htdocs/www/store/Smarty-2.6.12/Smarty.class.php on line
1095
and why are these characters displaying?
$i) \">

\n"; } ?>
i know it has to do with the print function, and that you have to tell the code to display corrrectly so you tell it to not read or print what's after the \ but i'm just not figuring out what i need to do to get this working.
anyone have any ideas?
thanks,