Showing posts with label Php. Show all posts
Showing posts with label Php. Show all posts
Load Youtube toprated videos using simplexml_load_file PHPView Comments
In this post I will show you how to fetch the you tube top rated videos just with built in PHP functions instead of using zend data api libraries. Zend data api is the best and optimized way to do this task but rather than including and working with zend and zend data api you can just do this with php built-in functions by reading the you tube feeds for the top rated videos.
So here we go. General feed url of youtube is http://gdata.youtube.com/feeds/api/standardfeeds/FEED_IDENTIFIER Youtube feeds URL for the top rated videos is http://gdata.youtube.com/feeds/api/standardfeeds/top_rated Here you can replace top_rated with Fore more info regarding this http://code.google.com/apis/youtube/2.0/developers_guide_php.html So we have to read the feeds from the above url, then you can display it where ever you want. We have the top rated videos as xml so we need to parse it using php function "simplexml_load_file() " . To do this in php.ini we need to enable the url include option to On if it is not already turned on. Get the feeds in a variable $url="http://gdata.youtube.com/feeds/api/standardfeeds/top_rated"; So we have top rated videos in $comments , we need to parse it using foreach and display it in the following way. Here the feed is in yahoo feed format so you to mention the feed as yahoo and then you can parse the media group under entry tag. $media = $video->children('http://search.yahoo.com/mrss/');So from this we can easily parse all the data from the youtube feeds. Download the source for your reference. ![]() You can also do all other functionality like searching a video or displaying particular video comments, recent videos and more using the above method. Its very easier than the zend data api. Try it out. Leave the comments if you have any problem Previous & Next Functionality with PHP, AJAX, JQuery and MySQLView Comments
Here i have designed a very simple application to fetch data from mysql server with php, through Ajax. In this application i have used two image input component for previous and next functionality and a table to display the data. Here is the preview of the application.
![]() ![]() You can download the application: ![]() On clicking the next button, the ajax function is called through this JQuery function $("#next").click(function(){It sends the index of the next set of data to fetch, to the ajax function. On success the data in the view is updated and the index of current data set is updated. The checkVisible function is to ensure the next previous functionality. i.e, the Next button will be disables on reaching the last data set and the previous button will be disable on reaching the first data set. function checkVisible(){In the ajaxpost file the MySql database fetch is executed. $limitquery = "select id,name,category,price,discount from previousnext limit ".(int)$_REQUEST['current'].",".$limit;The data send from sql server is parsed in the php file and send to the client. while($row = mysql_fetch_array($result)){In the next post i have planned to expand this application to have pagination. Donot forget to comment on my ideas. Steps to Install and Connect to PHP in Flex using AMFPHPView Comments
If you are bored of using XML to transfer data from PHP to Flex, then here is a end for your boredom. Using AMFPHP, you can convert data object in PHP to dataobject in action script so that you can use that in your flex project.
![]() ![]() ![]() Here are the steps to install and integrate AMFPHP with Flex.
Need php script to import csv/excel file into MysqlView CommentsUsing a script to parse and import the file If you need to take a csv or other delimited data file and import it INTO MySQL, here is a php script that can do it for you:
$connection = mysql_connect("localhost", "test", "test") or die ("Unable to connect to server");
$db = mysql_select_db("test", $connection) or die ("Unable to select database");
// first get a mysql connection as per the FAQ
$fcontents = file ('./spreadsheet.xls');
// expects the csv file to be in the same dir as this script
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode("\t", $line);
//if your data is comma separated instead of tab separated,
// change the '\t' above to ','
$sql = "insert into TABLENAME values ('".implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."\n";
if(mysql_error()) {
echo mysql_error() ."\n";
}
}
?> Note: Upload a spreadsheet file into the same directory as this script. Then you edit this script to put in the correct table name instead of "TABLENAME".
Subscribe to:
Posts (Atom)
About UsCategories
Followers |