View Full Version : mixing php with xml
pkcidstudio
09-27-06, 11:34 AM
has anyone had any experiance in mixing the two? how is it done? what is the best way? any tutorials or advise.
Christian
09-27-06, 04:15 PM
Here's a few to get you started:
http://www.zend.com/zend/tut/tutbarlach.php
http://www.zend.com/php5/articles/php5-xmlphp.php
http://www.kirupa.com/developer/php/php5_simpleXML.htm
http://www.wirelessdevnet.com/channels/wap/features/xmlcast_php.html
http://www.phpfreaks.com/tutorials/44/0.php
Mix in which way? To read the data from the XML file, or to generate a dynamic XML file for RSS or similar?
pkcidstudio
09-27-06, 05:18 PM
thankx for the links, there great-
any thoughts on if i want to limit what is in a rss feed would i just do a writing to another file from one file?
Oops:
ya more so to set things off on a timed type of thing sort of like that php script i wrote earlier and posted in php section. i want the server to limit what people see due to what day it is.
pkcidstudio
09-29-06, 04:55 PM
Mix in which way? To read the data from the XML file, or to generate a dynamic XML file for RSS or similar?
any thoughts for the rss feed with php running it ?
Here's a part of the script I use for the webisite of the company I work for. It might helps as example.
$result = mysql_query("SELECT * FROM yourtable WHERE something = 'something else'");
header('Content-type: text/xml; charset=iso-8859-1');
header('Expires: '. gmdate('D, d M Y H:i:s') .' GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo '<?xml version="1.0" encoding="iso-8859-1"?>' ."\r\n";
echo '<rss version="0.91">' ."\r\n";
echo "<channel>\r\n";
echo "\t<title>". sprintf('PROCOIM - '. $title[$lang], mysql_num_rows($result)) ."</title>\r\n";
echo "\t<link>http://www.procoim.com/</link>\r\n";
echo "\t<description>". $description[$lang] ."</description>\r\n";
echo "\t<language>". $langcode[$lang] ."</language>\r\n";
while ($propertyinfo = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "\r\n\t<item>\r\n";
echo "\t\t<title>". html_entity_decode($propertyinfo['name']) ." - ". $cats[$propertyinfo['category']] ."</title>\r\n";
echo "\t\t<link>http://www.procoim.com/catalogo.php?pid=". $propertyinfo['id'] ."&langid=". $lang ."</link>\r\n";
echo "\t\t<pubDate>" . gmdate('D, d M Y H:i:s', $propertyinfo['time']) ." GMT</pubDate>\r\n";
echo "\t\t<description>". html_entity_decode($propertyinfo['description']) ."</description>\r\n";
echo "\t</item>\r\n";
}
echo "</channel>\r\n";
echo "</rss>";
pkcidstudio
09-29-06, 05:42 PM
ok so do you just have all the feed in the table?
do you have this write to a xml file or where does it write to?
or does it change the type of file?
i think this is what ive been looking for just need a bit of direction.
this is great though
Well, this example works with a database. So you'd have to store your news or whatever in a table, yes. Just save it as "rss.php" for example, and open it in your browser. It's like an XML file, just with a php extension.
pkcidstudio
09-29-06, 08:16 PM
great ill let you know how it goes on monday. thankx nico
pkcidstudio
10-02-06, 11:52 AM
nico-
its working out well, but wondering if i am missing something. what does your table look like?
CREATE TABLE "table_name"
("column 1" "data_type_for_column_1",
"column 2" "data_type_for_column_2",
... )
thankx.
How my database looks like doesn't matter. What you have to do is to generate the XML values that are required for the feed. So every news item should have its own title, publication date, link and description. Once you have that, you can easily pull the content from the database and put it in the right fields.
pkcidstudio
10-02-06, 03:16 PM
that's, what I am learning. let me ask you a basic question though. how will it know to look for a different <item>...</item> each time instead of always grabbing the first? did I miss where that was in the code or does it know somehow. thankx for the help. almost done.
UnrealEd
10-03-06, 04:37 AM
what do you mean by grabbing the first? nico_swd's code loops over a section in the database, so it will display all items.
could you be a little more specific
UnrealEd
pkcidstudio
10-03-06, 09:48 AM
thankx for asking unrealEd, nico's code is great just what i am looking for. what i was asking was i have 10 <item>...</item> what would i put in that if that day is past show that <item>...</item> this is what i've added in but wondering if i am missing something.
$today = date('Ymd')
$result = mysql_query("SELECT * FROM myfreetrainer WHERE time = '". $today ."'"); basically that if it is that day or past it sow the <item></item> in the xml doc. also how do i get to run behind the scenes with out me going to the page to open the file. please advise if i need to be more specific.
UnrealEd
10-03-06, 10:06 AM
so you want to display all items larger then a given date?
$sql = "SELECT * FROM myfreetrainer WHERE time<='".date('YMd')."'";
if you want to run this fully automaticly, you'll have to use cronjob
or if you just want to run it whenever a use visits is, simply include the file in all files the user can visit.
UnrealEd
pkcidstudio
10-03-06, 10:46 AM
great, thank-
when you say "larger" do mean older than october 3rd i.e. 2nd 1st or do you mean october 4th, 5fth, ...
UnrealEd
10-03-06, 10:52 AM
i meant older, srry. As Ymd returns a number, older it should be :)
Greetz,
UnrealEd
pkcidstudio
10-03-06, 11:02 AM
right... cool... final question at least for a hour or so.
my primary should be time is that correct?
here is my sql table i am about to create. thankx for the help.
(
name varchar(60),
exercise varchar(60),
id varchar(60),
length varchar(10),
time date(yyyymmdd),
duration varchar(5),
keywords varchar(120),
)
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.