Reply to Re: XML create with PHP 5 help

Your name:

Reply:


Posted by Alistair Baillie SS2002 on 05/17/05 16:48

Assumint that the XML output will be approximatly the same, just use for
loops, to add the varying lengths.

IF you mean it will be totally different you could use 3Dimensional arrays,
and then generate the XML string from that.

other than these 2 methods, I'm afraid I cant help you. sorry.

Example for creating RSS output (not using 3d arrays):


<?php
/****
* Blog Off.net
*
* @author: Alistair Baillie
* @website: http://www.alistairbaillie.co.uk
* @version: 1.0
* @sourcepath: \\BO\
*
* The contents of this file and any associated files, including but in no
way
* limited to artwork and images, are copyright (c) 2005 Alistair D Baillie
* Any unauthorised reproduction or distribution is strictly prohibbited!
****/

$_BLOGOFF = true;

require("includes/comon.php");
header("Content-type: text/xml");

// Catch default blog request :)
if ( $_REQUEST['id'] == 0 ) {
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Blog Off.net</title>
<link>http://www.blogoff.net/</link>
<description>The 5 latest postings to Blog Off.net Journals</description>
<language>en-gb</language>

<?php
$query = $db->query("SELECT blogs_id, blogs_datetime, blogs_userid,
blogs_title, blogs_entry,
(SELECT Count(*) FROM bo_comments WHERE comments_blogid=row_x.blogs_id) as
numComments,
users_displayname FROM bo_blogs row_x, bo_users WHERE ( blogs_private=0
AND blogs_published=1 AND
users_id=blogs_userid )
ORDER BY blogs_datetime DESC LIMIT 5");

if ( $db->numrows( $query ) > 0 ) {
while ( $theData = $db->fetchrow( $query ) ) {
?>
<item>
<title><?php echo stripslashes( $theData['blogs_title'] ); ?></title>
<link>http://www.blogoff.net/index.php?bpost=<?php echo
$theData['blogs_id']; ?></link>
<description><?php echo stripslashes( $theData['blogs_entry'] );
?></description>
<dc:creator><?php echo stripslashes( $theData['users_displayname'] );
?></dc:creator>
<dc:date><?php echo date("Y-m-d", $theData['blogs_datetime']);
?></dc:date>
</item>
<?php
}
}
?>
</channel>
</rss>
<?php
}

if ( $_REQUEST['id'] > 0 ) {
$id = addslashes($_REQUEST['id']);
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Blog Off.net</title>
<link>http://www.blogoff.net/</link>
<description>The 5 latest postings to this persons blog!</description>
<language>en-gb</language>

<?php
$query = $db->query("SELECT blogs_id, blogs_datetime, blogs_userid,
blogs_title, blogs_entry,
(SELECT Count(*) FROM bo_comments WHERE comments_blogid=row_x.blogs_id)
as numComments,
users_displayname FROM bo_blogs row_x, bo_users WHERE ( blogs_private=0
AND blogs_published=1 AND
users_id=blogs_userid AND blogs_userid='$id' )
ORDER BY blogs_datetime DESC LIMIT 5");

if ( $db->numrows( $query ) > 0 ) {
while ( $theData = $db->fetchrow( $query ) ) {
?>
<item>
<title><?php echo stripslashes( $theData['blogs_title'] ); ?></title>
<link>http://www.blogoff.net/index.php?bpost=<?php echo
$theData['blogs_id']; ?></link>
<description><?php echo stripslashes( $theData['blogs_entry'] );
?></description>
<dc:creator><?php echo stripslashes( $theData['users_displayname'] );
?></dc:creator>
<dc:date><?php echo date("Y-m-d", $theData['blogs_datetime']);
?></dc:date>
</item>
<?php
}
}
?>
</channel>
</rss>
<?php
}
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация