Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post

    Is this right for making a php rss feed?

    Hey,

    I have a blog, and i let people subscribe via rss feed through feedburner.

    Now my rss feed is a php file, which basically connects to my blog database, and pulls out the latest 10 posts and displays them in a feed format.

    Now sometimes my feed kinda mucks up, and only displays one post or so and not 10, and sometimes it doesnt display at all.

    Can someone just check thorugh my script (below), and see if i have made any errors somewhere...

    PHP Code:
    <?
    $sqltable 
    "blog";
    $sqlretrieve "10";

    header("Content-type: text/xml");
    echo 
    "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";

    mysql_connect("localhost""database_username""database_password") or die(mysql_error());
    mysql_select_db("database_name") or die(mysql_error());

    echo 
    '<rss version="2.0">';

    echo 
    '<channel>
    <title>Kedoa Blog</title>
    <link>http://www.kedoa.com/blog</link>
    <description>Learn how to make money online, increase your website popularity and various marketing techniques by reading the Kedoa Blog.</description>
    <language>en-us</language>
    <copyright>Copyright: (C) Kedoa</copyright>'
    ;

    $data mysql_query("SELECT * FROM `$sqltable` ORDER BY id DESC LIMIT $sqlretrieve");

    while(
    $row mysql_fetch_array($data)) {

    $page $row[category];

    if (
    $page == 1) { ($blog "Apps")&&($blogcategory "1")&&($section_link "apps");
            } else if (
    $page == 2) { ($blog "Blogging")&&($blogcategory "2")&&($section_link "blogging");
            } else if (
    $page == 3) { ($blog "Design")&&($blogcategory "3")&&($section_link "design");
            } else if (
    $page == 4) { ($blog "Events")&&($blogcategory "4")&&($section_link "events");
            } else if (
    $page == 5) { ($blog "Flash")&&($blogcategory "5")&&($section_link "flash");
            } else if (
    $page == 6) { ($blog "Making Money")&&($blogcategory "6")&&($section_link "making-money");
            } else if (
    $page == 7) { ($blog "News")&&($blogcategory "7")&&($section_link "news");
            } else if (
    $page == 8) { ($blog "Ramblings")&&($blogcategory "8")&&($section_link "ramblings");
            } else if (
    $page == 9) { ($blog "Resources")&&($blogcategory "9")&&($section_link "resources");
            } else if (
    $page == 10) { ($blog "Reviews")&&($blogcategory "10")&&($section_link "reviews");
            } else if (
    $page == 11) { ($blog "Social Media")&&($blogcategory "11")&&($section_link "social-media");
            } else if (
    $page == 12) { ($blog "Technology")&&($blogcategory "12")&&($section_link "technology");
            } else if (
    $page == 13) { ($blog "Tips & Tricks")&&($blogcategory "13")&&($section_link "tips-tricks");
            } else if (
    $page == 14) { ($blog "Web")&&($blogcategory "14")&&($section_link "web");
            }

    date_default_timezone_set('Europe/London');
    $timestamp $row[posted];
    $pub date('D\, j M Y H\:i',$timestamp);
    $newrow html_entity_decode($row[full]);

    echo 
    '<item> // begins the item
    <link>http://www.kedoa.com/blog/'
    .$section_link.'/'.$row['url'].'</link>
    <title>'
    .$row['title'].'</title>
    <description><![CDATA['
    .$newrow.']]></description>
    <category>'
    .$blog.'</category>
    <pubDate>'
    .$pub.'</pubDate>
    </item>'
    ;
    }

    echo 
    '</channel></rss>';
    ?>

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    The only thing i can see needing changed is the big if elseif thing, use this instead:

    PHP Code:
    <?
    $sqltable 
    "blog";
    $sqlretrieve "10";

    header("Content-type: text/xml");
    echo 
    "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";

    mysql_connect("localhost""database_username""database_password") or die(mysql_error());
    mysql_select_db("database_name") or die(mysql_error());

    echo 
    '<rss version="2.0">';

    echo 
    '<channel>
    <title>Kedoa Blog</title>
    <link>http://www.kedoa.com/blog</link>
    <description>Learn how to make money online, increase your website popularity and various marketing techniques by reading the Kedoa Blog.</description>
    <language>en-us</language>
    <copyright>Copyright: (C) Kedoa</copyright>'
    ;

    $data mysql_query("SELECT * FROM `$sqltable` ORDER BY id DESC LIMIT $sqlretrieve");

    while(
    $row mysql_fetch_array($data)) {

    $page $row[category];

    //Build up an array of what each $blog is in relation to $blogcatagory:
    $blog_cats =  array(=> "Apps",
    => "Blogging",
    => "Design",
    => "Events",
    => "Flash",
    => "Money-Making",
    => "News",
    => "Ramblings",
    => "Resources",
    10 => "Reviews",
    11 => "Social-Media",
    12 => "Technology",
    13 => "Tips-Tricks",
    14 => "Web");

    //Add a small loop that will be faster than an if else eqivilent:
    for($i 1$i <= count($blog_cats); $i++){

      
    //Check the page against the variable i
      
    if($i == $page && $found != 1){
        
    $blog $blog_cats[$i];
        
    $blogcategory $i;
        
    $section_link str2lower($blog_cats[$i]);
        
    $found 1;
      }
    }

    date_default_timezone_set('Europe/London');
    $timestamp $row[posted];
    $pub date('D\, j M Y H\:i',$timestamp);
    $newrow html_entity_decode($row[full]);

    echo 
    '<item> // begins the item
    <link>http://www.kedoa.com/blog/'
    .$section_link.'/'.$row['url'].'</link>
    <title>'
    .$row['title'].'</title>
    <description><![CDATA['
    .$newrow.']]></description>
    <category>'
    .$blog.'</category>
    <pubDate>'
    .$pub.'</pubDate>
    </item>'
    ;
    }

    echo 
    '</channel></rss>';
    ?>
    That should be less labour intensive for the server
    Last edited by scoop_987; 07-26-2008 at 06:50 PM.

  • #3
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post
    Sweet, o you split it up into an array. I see what you have done. Thanks!

    So will this load alot faster now then?

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    not gonna say that, but it SHOULD be faster. But try and see, watch your server logs to see how much of a performance difference.

    and as for the little thing about not having any results, i couldn't find it at all.

    But try this instead, ive removed the SQL from the mysql_query and added the variable that i set before it with the SQL data in it, i always do that, easier for debugging.

    PHP Code:
    <? 
    $sqltable 
    "blog"
    $sqlretrieve "10"

    header("Content-type: text/xml"); 
    echo 
    "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"

    mysql_connect("localhost""database_username""database_password") or die(mysql_error()); 
    mysql_select_db("database_name") or die(mysql_error()); 

    echo 
    '<rss version="2.0">'

    echo 
    '<channel> 
    <title>Kedoa Blog</title> 
    <link>http://www.kedoa.com/blog</link> 
    <description>Learn how to make money online, increase your website popularity and various marketing techniques by reading the Kedoa Blog.</description> 
    <language>en-us</language> 
    <copyright>Copyright: (C) Kedoa</copyright>'

    $SQL "SELECT * FROM `".$sqltable."` ORDER BY `id` DESC LIMIT ".$sqlretrieve;
    $data mysql_query($SQL); 

    while(
    $row mysql_fetch_array($data)) { 

    $page $row[category]; 

    //Build up an array of what each $blog is in relation to $blogcatagory: 
    $blog_cats =  array(=> "Apps"
    => "Blogging"
    => "Design"
    => "Events"
    => "Flash"
    => "Money-Making"
    => "News"
    => "Ramblings"
    => "Resources"
    10 => "Reviews"
    11 => "Social-Media"
    12 => "Technology"
    13 => "Tips-Tricks"
    14 => "Web"); 

    //Add a small loop that will be faster than an if else eqivilent: 
    for($i 1$i <= count($blog_cats); $i++){ 

      
    //Check the page against the variable i 
      
    if($i == $page && $found != 1){ 
        
    $blog $blog_cats[$i]; 
        
    $blogcategory $i
        
    $section_link str2lower($blog_cats[$i]); 
        
    $found 1
      } 


    date_default_timezone_set('Europe/London'); 
    $timestamp $row[posted]; 
    $pub date('D\, j M Y H\:i',$timestamp); 
    $newrow html_entity_decode($row[full]); 

    echo 
    '<item> // begins the item 
    <link>http://www.kedoa.com/blog/'
    .$section_link.'/'.$row['url'].'</link> 
    <title>'
    .$row['title'].'</title> 
    <description><![CDATA['
    .$newrow.']]></description> 
    <category>'
    .$blog.'</category> 
    <pubDate>'
    .$pub.'</pubDate> 
    </item>'



    echo 
    '</channel></rss>'
    ?>

  • Users who have thanked scoop_987 for this post:

    Andy92 (07-26-2008)

  • #5
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post
    Ok ive put that code above.

    But when i view the file, it doesnt display any data?

    Can you see anything...

    http://www.kedoa.com/feedblog.php

    ??

    EDIT: Ah, i have looked at the source code and it says...

    Code:
    <b>Fatal error</b>:  Call to undefined function  str2lower() in <b>/home/kedoacom/public_html/feedblog.php</b> on line <b>49</b><br />
    I will try and fix this.

  • #6
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post
    Ok, i put strtolower instead of str2lower and it works great!

    Can you quickly go to...

    http://www.kedoa.com/feedblog.php

    And see if you can count 10 items?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •