PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 12th, 2012, 08:07 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
PHP-General - PHP with RSS/RDF - link as a variable

Hi!
I'm trying to create an RSS-feed with php, using information from a database. Basically I load link,title description,creator and feeddate from the database as $link, $title, $description etc.. The $link is Primary Key in the database and contains a link to a pdf or doc.
This is together creating a bunch of news articles, which I want to create an RSS-feed with.

I want to use RDF to do this and my problem is that I'm trying to use the $link variable, and I can't get it to work.
I call a function with: news($link)
and the function looks like this:


function news(<?php $newslink ?>){
<channel>
<items>
<rdf:Seq>
<rdf:li rdf:resource="<?php $newslink ?>"/>
</rdf:Seq>
</items>
</channel>

<item rdf:about="<?php $newslink ?>">
<title><?php $title ?></title>
<link><?php $newslink ?></link>
<description><?php $description ?></description>
<dc:creator><?php $creator ?></dc:creator>
<dc:date><?php $feeddate ?></dc:date>
</item>
}


My problem is the links (I think) and getting the $link-variable to work properly. As for now, it doesn't work at all and I can not understand why. The reason I'm using a function for this is because I want to do the same thing for all of the news. I'm pretty new to this.

Reply With Quote
  #2  
Old November 12th, 2012, 08:47 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
You need to include the whole function as part of the PHP code to call it from PHP elsewhere.
PHP Code:
<?php
function news($newslink){
echo 
"
<channel>
<items>
<rdf:Seq>
<rdf:li rdf:resource=\"
$newslink\"/>
</rdf:Seq>
</items>
</channel>

<item rdf:about=\"
$newslink\">
<title>
$title</title>
<link>
$newslink</link>
<description>
$description</description>
<dc:creator>
$creator</dc:creator>
<dc:date>
$feeddate</dc:date>
</item>"
;
}
?>

Note the use of [ PHP ] tags for the code. See ManiacDan's New User Guide.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old November 12th, 2012, 09:48 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
The PHP tags I already had, just forgot to mention that.
But the rest helped me alot, thanks!

Reply With Quote
  #4  
Old November 15th, 2012, 06:36 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
Problem with rdf:li adding links

I now have a new problem (probably the last one before this is working as I want it to). I have changed the way I handle the links from the database a little. The links is stored in the variable $link which passes this on to an array $links[]. In this array I store all of the links and from there I want to put each array element in to the rdf:li, as separate rdf:li elements.
The problem is that I want to do this before I actually read it from the database.
Here's my code:

<channel>
//some channel elements code that's not interesting//
PHP Code:
<?php
echo "
<items> 
    <rdf:Seq> 
        <rdf:li rdf:resource=\"
$links[0]\"/>
        <rdf:li rdf:resource=\"
$links[1]\"/>
        <rdf:li rdf:resource=\"
$links[2]\"/>
        <rdf:li rdf:resource=\"
$links[3]\"/>
    </rdf:Seq> 
</items> 
</channel>"
;
?>


And a bit further down:

$result = mysql_query($query)
or die("Query failed");

$i = 0;

PHP Code:
<?php
while ($line mysql_fetch_object($result)) {
        
$link $line->link
        
$link1 ereg_replace (' ''%20'$link);
        
$title $line->title;
        
$description $line->description;
        
$description1 ereg_replace ('&''&'$description);
        
$creator $line->creator;
        
$feeddate $line->feeddate;
        
$feeddate1 strftime(strtotime($feeddate));
         
        
$links[$i] = $link1;
        
$i++;
        
        echo 
"
        <item rdf:about=\"
$link1\"> 
            <title>
$title</title> 
            <link>
$link1</link> 
            <description>
$description1</description> 
            <dc:creator>
$creator</dc:creator> 
            <dc:date>
$feeddate1</dc:date> 
        </item>"

    }
?>


In this case I have 4 links that I'm reading from the database. These links I want to put in to the rdf:li elements at the top, and then I want the rest to happen. The problem is that I don't know how to put it above "the rest", since the array is empty before I've read it from the database. I get a feeling that this is something simple I have missed, but I can't find any help by searching.

Reply With Quote
  #5  
Old November 15th, 2012, 07:04 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
I don't understand. Why not put the list after the query or the query before the list?

Reply With Quote
  #6  
Old November 15th, 2012, 07:20 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
I don't understand. Why not put the list after the query or the query before the list?


The reason I want to do it in that order is because I want it to look exactly like an xml-file I already have (in the structure), but still I want to generate these links, instead of just writing them in the code. My aim is to achieve this special order of the elements, where I need the list to be at the top, and then define each of the links with their attributes such as description and title.

The result doesn't look good if I define the list after the separate links have been defined with their attributes. Hope you understand.

Reply With Quote
  #7  
Old November 15th, 2012, 07:23 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
My output structure that I'm talking about is the source code of the RSS-feed that's created with this PHP-file. This output structure is supposed to look like the xml-file I'm aiming for.

Reply With Quote
  #8  
Old November 15th, 2012, 07:39 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
Sorry for being dense but I still don't see how where you put the database query has anything to do with what the output looks like. The client does not know anything about the query, only the output result.

Reply With Quote
  #9  
Old November 15th, 2012, 07:54 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
Okay, maybe my explanation was not spot on. When I look at the source code of the RSS-feed I can see the elements channel, items, item, list, and so on. Of course I can't see the php-code in the source code. The things that I "echo" in my code though, exists in the source code. Everything works just fine, except that the rdf:li-elements misses the links, since the array is empty when I "echo" this.

Reply With Quote
  #10  
Old November 15th, 2012, 08:01 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
Now I'm really confused. Are you writing the PHP code and query or are you trying to screen scrape the data from some other site?

Reply With Quote
  #11  
Old November 15th, 2012, 08:09 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Now I'm really confused. Are you writing the PHP code and query or are you trying to screen scrape the data from some other site?


I am writing the PHP code and query. From earlier I have an xml-file with the same info that is in my database, but in hardcore code. In this xml-file all info is coded, nothing is taken from my database. Now I want to do the same thing but read the info from my database instead of coding everything, to learn and see if I can get the same results with PHP and query, as I got with xml. All files are my own.

Reply With Quote
  #12  
Old November 15th, 2012, 08:21 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
I guess I am missing something as this brings me back to my original suggestion. If you are building the page, then what prevents you from moving the query so that it populates the link array before you use it.

Reply With Quote
  #13  
Old November 15th, 2012, 09:21 AM
emilagren emilagren is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 14 emilagren User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 9 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
I guess I am missing something as this brings me back to my original suggestion. If you are building the page, then what prevents you from moving the query so that it populates the link array before you use it.


Maybe I just misunderstood what you said at first, but now I think I got what you mean. I solved it just now by doing a special query at the top handling only the links. Very basic. Sometimes I just have trouble with the "thinking as a programmer" part, heh. Thanks alot for your help!

Reply With Quote
  #14  
Old November 15th, 2012, 09:25 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,867 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 9 h 6 m 6 sec
Reputation Power: 581
I hope you are not doing a double query. Everything you get from the database can be done with a single query, put into an array (or perhaps better yet into an array of objects - learn some OOP here) and then used elsewhere as needed.

One more note. You should not be using the depreciated MySQL extensions. Instead switch to PDO (another OOP learning opportunity).

Last edited by gw1500se : November 15th, 2012 at 09:27 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - PHP with RSS/RDF - link as a variable

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap