Home arrow MySQL arrow Page 3 - Build Your Own KlipFolio Klip With PHP
MYSQL

Build Your Own KlipFolio Klip With PHP


You all know Frank as our DevXPress editor, but we managed to get him writing articles too! Today he shows us how to create our own KlipFolio Klip with PHP and MySQL.

Author Info:
By: Frank Manno
Rating: 5 stars5 stars5 stars5 stars5 stars / 14
November 23, 2002
TABLE OF CONTENTS:
  1. · Build Your Own KlipFolio Klip With PHP
  2. · Creating a Klip with an Existing XML Feed
  3. · Testing Your Klip
  4. · Conclusion

print this article
SEARCH DEVARTICLES

Build Your Own KlipFolio Klip With PHP - Testing Your Klip
(Page 3 of 4 )

In order to successfully test the Klip yourself, you will need to install the KlipFolio software on your system. At this point, KlipFolio is only available for Windows-based systems, although Serence does plan on releasing KlipFolio for other operating systems in the near future.

The testing process can be done on any server of your choice, whether it be your own personal server or your host's server. Simply upload the Klip to a directory and click the link to the file. It should automatically load itself as a Klip and start displaying your content feeds. Be sure to check that all is as expected by clicking on the headline links, as well as entering the Klip setup to ensure that the banner and "About" information are properly displayed.

The last step in setting up your Klip is simple. Serence provides a Klip repository that they have dubbed as the "KlipFarm". As a content provider, you have the option of signing up for a provider account. The registration is free and provides you with a slick interface for uploading and updating your Klip. Once your Klip has been uploaded, you are presented with several options including: make available and make button. The first adds your Klip to the public listing in the KlipFarm. The latter provides you with several options for generating code to display a button or banner on your site so that users may add your Klip to their folio (Check the very bottom of this page for the klip logo that links to our klip).



Although creating your Klip with an existing content feed is the quickest method available, it isn't an option available to all. Continue reading to learn another approach.

Creating a Klip by Creating Your Own Content Feed
If you don't have an existing content feed setup, there is an alternative to building your own Klip. In this section I'll show you how it's possible to create a Klip information channel using PHP and MySQL to retrieve your content from a database.

First, we'll create a small sample database-driven content feed. Load up your favourite MySQL interface tool and create a new database named content:

create database content;
use content;


Next, we'll create a new table called news_items. This is the table that will contain your content that will be used by the Klip:

create table news_items(
news_id int auto_increment not null primary key,
news_title varchar(100),
news_content text);


We'll add some sample content to the database:

insert into news_items values (0, 'IBM extends its server lead', 'Big Blue bolsters its first-place ranking in a worldwide server market that shrank 3 percent in the most recent quarter. Dell also manages to nab more turf.');

insert into news_items values (0, 'MS teases 64-bit Net Server for AMD', 'Will Microsoft offer a version of .Net Server for the AMDs 64-bit processors? The company won''t say, but according to the Windows boss... it could');

insert into news_items values (0, 'Ruin your PC with an Aqua Dock', 'Because a small number of sites continue to produce knock-offs of the Aqua UI. On two of the most popular, Aqua-Man and Emaculation, you can find work in progress to bring Aqua controls, and even basic versions of the iApps bundle to Windows.');


Next, we'll create the PHP script that will retrieve the values from the database and create the Klip file. Copy and paste the following code into your favorite editor and save the file as content_feed.php:

<?php

$dbServer = "localhost";
$dbName = "content";
$dbUser = "dbuser";
$dbPass = "dbpass";

$dbcnx = @mysql_connect($dbServer, $dbUser, $dbPass) or die("Could not connect to database server!");
$dbsel = @mysql_select_db($dbName, $dbcnx) or die("Error connecting to database");

/** Retrieve result set from database containing Klip content
* title and link information */
$query = "SELECT news_id, news_title FROM news_items ORDER BY news_id DESC LIMIT 10";

/** Parse result set to create Klipfood content */
echo("<klipfood>\n");

$result = @mysql_query($query);

while ($row = mysql_fetch_array($result)){
$newsId = $row['news_id'];
$title = str_replace("\"", "\\\"", $row['news_title']);
echo(" <item>\n");
echo(" <title>\n");
echo(" $title\n");
echo(" </title>\n");
echo(" <link>\n");
echo(" http://nwp.frankmanno.com/viewnews.php?newsId=$newsId\n");
echo(" </link>\n");
echo(" </item>\n\n");
}
echo("</klipfood>\n");
?>


We'll take a closer look into the code so you can understand exactly what's happening:

<?php

$dbServer = "localhost";
$dbName = "dbname";
$dbUser = "dbuser";
$dbPass = "dbpass";

$dbcnx = @mysql_connect($dbServer, $dbUser, $dbPass) or die("Could not connect to database server!");
$dbsel = @mysql_select_db($dbName, $dbcnx) or die("Error connecting to database");

/** Retrieve result set from database containing Klip content
* title and link information */
$query = "SELECT news_id, news_title FROM news_items ORDER BY news_id DESC LIMIT 10";


This block of code connects to your database server and retrieves the first 10 records from the news_items table. I would recommend using some form of error handling, just like I have using the die() function.

Although I've used a limit of 10 for the number of records retrieved, fell free to change this to whatever amount you like.

/** Parse result set to create Klipfood content */
echo("<klipfood>\n");

$result = @mysql_query($query);

while ($row = mysql_fetch_array($result)){
$newsId = $row['news_id'];
$title = str_replace("\"", "\\\"", $row['news_title']);
echo(" <item>\n");
echo(" <title>\n");
echo(" $title\n");
echo(" </title>\n");
echo(" <link>\n");
echo(" http://www.yourwebsite.com/viewnews.php?newsId=$newsId\n");
echo(" </link>\n");
echo(" </item>\n\n");
}
echo("</klipfood>\n");
?>


This last block of code uses the retrieved result set to create the "KlipFood" tags required to display your content in the Klip Information Channel. The one thing to make note of is the use of the str_replace function, which will escape any quotes in your content titles. This eliminates any display problems and ensures your visitors will see your content.

The next step is to modify your template.klip file and change the following lines so that the Klip information channel receives its information from your newly created PHP content feed:

<contentsource>
<!--the url for the KlipFood this Klip uses-->
http://www.devarticles.com/feeds/content_feed.php
</contentsource>


Save the file, and test the Klip using a copy of the KlipFolio software. Once testing is complete, be sure to upload the Klip using your Serence Provider Account. Once uploaded, add your Klip to the public KlipFarm and add the KlipFolio button to your website so that visitors may add your Klip.
blog comments powered by Disqus
MYSQL ARTICLES

- MySQL and BLOBs
- Two Lessons in ASP and MySQL
- Lord Of The Strings Part 2
- Lord Of The Strings Part 1
- Importing Data into MySQL with Navicat
- Building a Sustainable Web Site
- Creating An Online Photo Album with PHP and ...
- Creating An Online Photo Album with PHP and ...
- PhpED 3.2 More Features Than You Can Poke ...
- Creating An Online Photo Album with PHP and ...
- Creating An Online Photo Album with PHP and ...
- Security and Sessions in PHP
- Setup Your Personal Reminder System Using PHP
- Create a IP-Country Database Using PERL and ...
- Developing a Dynamic Document Search in PHP ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials