Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php
include_once("config.php");

$videoDetailsStr = $_POST['videoDetailsData'];

$videoDetails = explode(",",$videoDetailsStr);
              
$thumbnailImage = mysql_real_escape_string($videoDetails[0]);

$title = mysql_real_escape_string($videoDetails[1]);

$category = mysql_real_escape_string($videoDetails[2]);

$description = mysql_real_escape_string($videoDetails['3']);

$videoLink = mysql_real_escape_string($videoDetails['4']);

$result = mysql_query("INSERT into videoDetails(thumbnailImage,title,category,description,videoLink) 				values('$thumbnailImage','$title','$category','$description','$videoLink')");

if($result)
{
echo "success";
}

mysql_close();
?>

My Videoportal.php code
JavaScript
<!--Here is my jQuery-->
<script>
jQuery(document).ready(function() 
{
   jQuery.ajax(
   {
      type: 'GET',
      url: 'category.php',
      dataType: 'JSON',
      success:function(data)
      {
         for(i=0;i<jquery(data).length;i++)>
         {
            $('#parentCategory').append('<option value = '+ data[i].category_name+'>' + data[i].category_name + '</option>');
         }
      }
   });
});
</script>

<script>
jQuery(document).ready(function() 
{
   jQuery('#parentCategory').change(function()
   {
     jQuery("#subCategory").load("subcategory.php? choice="+jQuery("#parentCategory").val());
   });
});
</script>

<script>
jQuery(document).ready(function()
{
   jQuery('#submit').click(function()
   {
      var videoDetails =[];
      jQuery('.mycheckbox').each(function()
      { 	
         if (this.checked == true)
         {
            var thumbnailImage =jQuery (this).parent(). find('table').find ('tbody').find('tr').find('td:first').find('img').prop("src");

            var title=jQuery(this).parent() .find('table').find('tbody').find('tr') .find('td:nth(1)').find('p:nth(0)').html();

            var category=jQuery(this).parent().find('table') .find('tbody').find ('tr').find('td:nth(1)').find('p:nth(1)').html();

            var  description=jQuery(this). parent().find('table'). find('tbody'). find('tr').find('td:nth(1)').find('p:nth(2)').html();

            var videoLink=jQuery(this).parent(). find('table').find('tbody').find ('tr').find('td:nth(1)').find('p:nth(3)').find('a').prop("href");

            videoDetails.push(thumbnailImage);
            videoDetails.push(title);
            videoDetails.push(category);
            videoDetails.push(description);
            videoDetails.push(videoLink);
				
            //alert(videoDetails);
         }
       });

      var jsonString = JSON.stringify(videoDetails);

      jQuery.ajax(
      { 
         type: 'POST',
         url: 'result.php',
         data: {'videoDetailsData': jsonString},
         success: function(data)
         {
            if(data=="success")
            {
               alert("Data stored successfully");
            }
         },
         error: function(xhr, textStatus, errorThrown) 
         {
            alert('An error occurred! ' + ( errorThrown ? errorThrown :xhr.status));
         }		
      });
   });
});
</script>


[edit]indexation reduced[/edit]




//My videoportal.php full code


$base_path = "/home/path"; // absolute base / root path
$cache_folder = "videoportal"; // create this folder under your base path folder, chmod this folder 777.
$page_name = "videoportal.php"; // script name, if you change the name of the script please reflect the change also here.
$max_cache_time = 0; // disable the cache by setting to 0 seconds.
$max_results = 6; // max results to return on one page.
$max_files_directory = 1000; // for cache path determination, max. files in one directory, you can leave this by default unless you use reiserfs.
$title = "Video Portal"; // title for your videoportal.
$header_image = ""; // if you prefer an header image just define the name or the full url path here.

// upload your videoportal.php script and if necessary your header image file to the $cache_folder you have created.
// then just call your script from the browser and enjoy youtube content at your website.

// reference for the api at http://code.google.com/apis/youtube/reference.html
// if you need help or have questions send an mail to deschakovskiholger@freenet.de
// you can change the layout, the html part is starting from around line 643
// END OF SETUP.


// standard feed urls.
$base_feed_url = "http:\/\/gdata\.youtube\.com\/feeds\/api\/";
$base_feed_url1 = "http://gdata.youtube.com/feeds/api/";

$top_rated = "standardfeeds/top_rated";
$top_favorites = "standardfeeds/top_favorites";
$most_viewed = "standardfeeds/most_viewed";
$most_discussed = "standardfeeds/most_discussed";
$most_linked = "standardfeeds/most_linked";
$most_responded = "standardfeeds/most_responded";
$recently_featured = "standardfeeds/recently_featured";

/*$display_allways = "";
$display_allways .= "Top Rated | \n";
$display_allways .= "Top Favorites | \n";
$display_allways .= "Most Viewed | \n";
$display_allways .= "Most Discussed | \n";
$display_allways .= "Most Linked | \n";
$display_allways .= "Most Responded | \n";
$display_allways .= "Recently Featured

\n";*/

$display_allways .= "<form action=\"".$page_name."\" method=\"get\">\n";
$display_allways .= "<input type=\"text\" name=\"u\" size=\"40\"></input>\n";
$display_allways .= "order by <select name=\"orderby\">\n";
$display_allways .= "<option>relevance</option><option>published</option><option>rating</option><option>viewCount</option>\n";
$display_allways .= "</select>\n";
$display_allways .= "<input type=\"hidden\" name=\"search\" value=\"1\">\n";
$display_allways .= "<input name=\"submit\" type=\"submit\" value=\"search videos\"></input>\n";
$display_allways .= "</form>\n";
//$display_allways .= "You can use the Boolean OR ' | ' and NOT ' - ' Operator for your Search.
\n";
//$display_allways .= "For Example to search for Videos matching either 'boating' or 'sailing' but not 'fishing', type 'boating|sailing -fishing'.

\n";

if ( ! $_GET['u'] ) { $url_to_get = $base_feed_url1.$recently_featured; $_GET['u'] = $recently_featured; }
else {

if ( $_GET['search'] ) {

$search_term = preg_replace('/^\s+/', '', strtolower($_GET['u']));
$search_term = preg_replace('/\s+$/', '', $search_term);
$search_term = preg_replace('/\s*\|\s*/', '|', $search_term);
$search_term = preg_replace('/\-\s+/', '-', $search_term);
$search_term = preg_replace('/\s+/', ' ', $search_term);

$url_to_get = $base_feed_url1."videos?vq=".urlencode($search_term);
$url_to_get .= "&orderby=".$_GET['orderby'];
$_GET['u'] = urlencode($search_term)."&orderby=".$_GET['orderby']."&search=".$_GET['search'];
}
else { $url_to_get = $base_feed_url1.$_GET['u']; }
}

// determine the start index.
if ( ! $_GET['p'] ) { $actual_page = 1; }
else { $actual_page = $_GET['p']; }

if ( ! preg_match('#/users/([^/]+)$#', $url_to_get) &&
! preg_match('#/videos/([^/]+)$#', $url_to_get) ) {

$start_index = (($actual_page - 1) * $max_results) + 1;
if ( $_GET['search'] ) { $url_to_get .= "&"; }
else { $url_to_get .= "?"; }
$url_to_get .= "start-index=".$start_index."&max-results=".$max_results;
}

// encode the url to an filepath.
$file_path_start = preg_replace('#^'.$base_feed_url.'#', '', $url_to_get) or die();
$encoded_fps = preg_replace('/\./', '', encode_ord($file_path_start));
$file_path = make_path($encoded_fps);
$file_path .= ".txt";

//print "".$file_path_start." -> ".$encoded_fps." -> ".$file_path."
\n";

// check if the file got to be updated.
$actual_time = time();
$file_update = 1;

if ( file_exists($base_path."/".$cache_folder."/".$file_path) ) {

$file_create_time = filectime($base_path."/".$cache_folder."/".$file_path);
if ( ! $file_create_time ) { $file_create_time = 0; }
$cache_time = $actual_time - $file_create_time;
if ( $cache_time < $max_cache_time ) { $file_update = 2; }

//print "file exists: create time -> ".$file_create_time." cached time -> ".$cache_time."
\n";
}

//print "update: $file_update
\n";

// read content from cache or get the url.
$response = "";

if ( $file_update == 2 ) {

//print "read from cache
\n";
$response = file_get_contents($base_path."/".$cache_folder."/".$file_path);
//print "response: $response
\n";

$response_array = explode("<:::split:::>", $response) or die();
$display = $response_array[0] or die();
$display_store_string = $response_array[1] or die();
$feed_details['title'][1] = $response_array[2] or die();
}

if ( ! $response ) {

//print "read from youtube
\n";
$response = file_get_contents($url_to_get);
//print "response: $response
\n";

$response = preg_replace('/\\n/', '', $response);

$feed_details = array();
preg_match("/<title type='text'>(.+?)<\/title>/", $response, $feed_details['title']);
preg_match("/<link rel='alternate' type='text\/html' href='(.+?)'\/>/", $response, $feed_details['url']);
preg_match('/<opensearch:totalresults xmlns:opensearch="#unknown">(.+?)<\/openSearch:totalResults>/', $response, $feed_details['results']);
preg_match('/<updated>(.+?)<\/updated>/', $response, $feed_details['updated']);

$feed_details['bl1'] = 'Download this Youtube PHP Script';
$feed_details['bl2'] = 'Amidalla Search - Suchmaschine';
$feed_details['bl3'] = 'Arcade Games';

$video_items = array();
preg_match_all('/<entry.*?>(.+?)<\/entry>/', $response, $video_items);

// print feed details.
/*$display = "";
$display .= "".$feed_details['title'][1]."
\n";
$display .= "Go directly to this Page at Youtube:\n";
$display .= "".$feed_details['url'][1]."
\n";
$display .= "This Content were updated ".$feed_details['updated'][1]." at Youtube.
\n";*/

if ( $start_index ) {

// $display .= "Total Results ".$feed_details['results'][1];

//$end_results = $start_index + $max_results - 1;
if ( $end_results > $feed_details['results'][1] ) { $end_results = $feed_details['results'][1]; }

//$display .= ", displaying Results from ".$start_index." to ".$end_results.".

\n";
//$display .= $feed_details['bl1']." | ".$feed_details['bl2']." | ".$feed_details['bl3']."

\n";
}

// navigation
if ( $video_items && $feed_details['results'][1] ) {

$max_pages = $feed_details['results'][1] / $max_results;
if ( strstr($max_pages, ".") ) { $max_pages++; }

$navi_pass = $_GET['u']; #urlencode($_GET['u']);

$display .= "PAGES:";

if ( $actual_page > 1 ) {

$previous_page = $actual_page - 1;
$display .= " previous\n";
}

for ( $pc=$actual_page; $pc <= $actual_page + 5; $pc++ ) {

if ( $pc > $max_pages ) { break; }
else {

if ( $pc == $actual_page ) { $display .= " ".$pc; }
else { $display .= " ".$pc."\n"; }
}
}

if ( ($actual_page + 1) <= $max_pages ) {

$next_page = $actual_page + 1;
$display .= " next\n";
}
}

$video_items1 = array();
$video_items1 = preg_split('//print_r($feed_details);
//print_r($video_items1);
//print_r($video_items);

// parse all tags.
$display_store = array();

for ($vic=0; $vic < count($video_items[1]); $vic++) {

$embraced_video_details = array();
preg_match_all('/<(.+?)>([^<>]+)<\/\\1>/', $video_items[1][$vic], $embraced_video_details);

$embraced_video_details1 = array();
preg_match_all('/<(.+?)\s.+?>([^<>]+)<\/\\1>/', $video_items[1][$vic], $embraced_video_details1);

$embraced_video_details2 = array();
preg_match_all('/<([^<>]+)\/>/', $video_items[1][$vic], $embraced_video_details2);

$evd_named = array();
for ( $evdc=0; $evdc < count($embraced_video_details[1]); $evdc++ ) {

if ( strstr($embraced_video_details[1][$evdc], " ") ) {

$embraced_video_details[1][$evdc] = preg_replace('/\s+/', '_', $embraced_video_details[1][$evdc]);
}

$evd_named[$embraced_video_details[1][$evdc]] = $embraced_video_details[2][$evdc];
}

for ( $evdc=0; $evdc < count($embraced_video_details1[1]); $evdc++ ) {

if ( strstr($embraced_video_details1[1][$evdc], " ") ) {

$embraced_video_details1[1][$evdc] = preg_replace('/\s+/', '_', $embraced_video_details1[1][$evdc]);
}

$evd_named[$embraced_video_details1[1][$evdc]] = $embraced_video_details1[2][$evdc];
}

for ( $evdc=0; $evdc < count($embraced_video_details2[1]); $evdc++ ) {

$item_info = array();
preg_match_all('/(.+?)=\'(.+?)\'\s*/', $embraced_video_details2[1][$evdc], $item_info);

//print_r($item_info);

for ( $iic=0; $iic < count($item_info[1]); $iic++ ) {

if ( strstr($item_info[1][$iic], " ") ) {

$item_info[1][$iic] = preg_replace('/\s+/', '_', $item_info[1][$iic]);
}

if ( $item_info[1][0] == $item_info[1][$iic] ) { $evd_named[$item_info[1][0]][$item_info[1][$iic]][] = $item_info[2][$iic]; }
else { $evd_named[$item_info[1][0]][$item_info[1][$iic]][$item_info[2][0]] = $item_info[2][$iic]; }
}
}

//print_r($embraced_video_details);
//print_r($embraced_video_details1);
//print_r($embraced_video_details2);
//print_r($evd_named);

if ( preg_match('#/standardfeeds/([^/]+)$#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/playlists/([^/]+)$#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/users/.+?/favorites#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/users/.+?/uploads#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/users/.+?/subscriptions#', $url_to_get) ) { $display_store[] = display_as_sub( $evd_named ); }
if ( preg_match('#/users/.+?/contacts#', $url_to_get) ) { $display_store[] = display_as_contact( $evd_named ); }
if ( preg_match('#/users/.+?/playlists#', $url_to_get) ) { $display_store[] = display_as_playlist( $evd_named ); }
if ( preg_match('#/users/([^/]+)$#', $url_to_get) ) { $display_store[] = display_as_user( $evd_named ); }
if ( preg_match('#/videos/([^/]+)$#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/videos/\-/.+?#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/videos\?vq=.+?#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/videos/.+?/related#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/videos/.+?/responses#', $url_to_get) ) { $display_store[] = display_as_video( $evd_named ); }
if ( preg_match('#/videos/.+?/comments#', $url_to_get) ) {

$display_store[] = display_as_comment( $evd_named );

if ( $vic == 0 ) {

$key = $evd_named['link_rel']['link_rel'][0];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $evd_named['link_rel']['href'][$key]) or die ();

$display .= "

VIDEO COMMENTS\n";
$display .= " | RELATED VIDEOS
\n";

$key = $evd_named['link_rel']['link_rel'][1];
$display .= "Watch commented Video at Youtube\n";

$video_title_array = array();
preg_match("/Comments on '(.+?)'/", $feed_details['title'][1], $video_title_array);

$video_id_array = explode("=", $evd_named['link_rel']['href'][$key]);
$video_id = $video_id_array[ count($video_id_array) - 1 ];

$pass_js_title = encode_ord($video_title_array[1]);
$pass_js_videourl = encode_ord("http://www.youtube.com/v/".$video_id);

$display .= " | $display .= "PLAY COMMENTED VIDEO

\n";
}
}
}

$display_store_string = "";
foreach ( $display_store as $ds ) { $display_store_string .= $ds;}

if ( $max_cache_time > 0 ) {

folder_create( $base_path."/".$cache_folder, $file_path, 0777);

// store data to an text file.
$store = fopen($base_path."/".$cache_folder."/".$file_path, "w") or die();
flock ($store, LOCK_EX) or die();
fputs ($store, $display."<:::split:::>".$display_store_string."<:::split:::>".$feed_details['title'][1]) or die();
fclose($store) or die();
}
} // $file_update == 1, read from youtube and parse content.


// functions and classes.
function display_as_video ( &$tag_array ) {

global $base_feed_url;

$display_string = "";
//$display_string .= '

';
$display_string .= "
$display_string .= '
<input type="checkbox" class="mycheckbox" name="check">
';

$video_url = $tag_array['media:content_url']['media:content_url'][0];

if ( $video_url ) {

$pass_js_title = encode_ord($tag_array['title']);
$pass_js_videourl = encode_ord($video_url);

$display_string .= "
$display_string .= "<img src=\"".$tag_array['media:thumbnail_url']['media:thumbnail_url'][0]."\"";
$display_string .= " border=\"0\" alt=\"Play ".$tag_array['title']."\">

\n";

$display_string .= "

//$display_string .= '

';


//$display_string .= "<img src=\"".$tag_array['media:thumbnail_url']['media:thumbnail_url'][1]."\"";
//$display_string .= " border=\"0\" alt=\"Play ".$tag_array['title']."\">

\n";

//$display_string .= "
}
else {

$display_string .= "<img src=\"".$tag_array['media:thumbnail_url']['media:thumbnail_url'][0]."\"";
$display_string .= " border=\"0\" alt=\"".$tag_array['title']."\">

\n";
//$display_string .= "<img src=\"".$tag_array['media:thumbnail_url']['media:thumbnail_url'][1]."\"";
//$display_string .= " border=\"0\" alt=\"".$tag_array['title']."\">

\n";
}


$display_string .= "\n";

$display_string .= "TITLE:

".$tag_array['title']."

"."
\n";

$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['uri']) or die();

// $display_string .= " USER:
".$tag_array['name']."
\n";

$category_string .= urlencode("videos/-/".$tag_array['media:category']);
$display_string .= "CATEGORY:";
$display_string .="

".$tag_array['media:category']."

"."
\n";

$keywords = preg_replace('/\s+/', '', $tag_array['media:keywords']);
$keywords_array = explode(",", strtolower($keywords));
$keywords_string = "";
foreach ( $keywords_array as $kw_value ) {

$keyword = urlencode("videos/-/".$kw_value);
$keywords_string .= "".$kw_value." ";
}

//$display_string .= " KEYWORDS: ".$keywords_string."
\n";
$display_string .= "DESCRIPTION:

".$tag_array['media:description']."

"."
\n";

//$display_string .= "PUBLISHED: ".$tag_array['published'];
//$display_string .= " UPDATED: ".$tag_array['updated']."
\n";

//$key = $tag_array['yt:statistics_favoriteCount']['yt:statistics_favoriteCount'][0];
//$display_string .= "VIEW COUNT: ".$tag_array['yt:statistics_favoriteCount']['viewCount'][$key];
//$display_string .= " FAVOURITE COUNT: ".$key."
\n";

//$display_string .= "RUNTIME: ".$tag_array['yt:duration_seconds']['yt:duration_seconds'][0]." sec.";


//$key = $tag_array['gd:rating_average']['gd:rating_average'][0];
// $display_string .= " RATING: ".$key;
// $display_string .= " NO.: ".$tag_array['gd:rating_average']['numRaters'][$key]."
\n";

$key = $tag_array['gd:feedLink_href']['gd:feedLink_href'][0];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $key);

//$display_string .= "COMMENTS

";
// $display_string .= " NO.:

".$tag_array['gd:feedLink_href']['countHint'][$key];

$key = $tag_array['link_rel']['link_rel'][1];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['link_rel']['href'][$key]) or die ();

//$display_string .= " VIDEO COMMENTS\n";

$key = $tag_array['link_rel']['link_rel'][2];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['link_rel']['href'][$key]) or die ();

//$display_string .= " RELATED VIDEOS

\n";

$display_string .= "Watch this Video at Youtube
\n";

$display_string .= "









\n";

return $display_string;
}

function display_as_comment ( &$tag_array ) {

global $base_feed_url;

$display_string = "";
$display_string .= "

$display_string .= "
\n";

$display_string .= "TITLE: ".$tag_array['title']."";

$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['uri']) or die ();

$display_string .= " USER: ".$tag_array['name']."
\n";
$display_string .= "COMMENT: ".$tag_array['content']."
\n";

$display_string .= "PUBLISHED: ".$tag_array['published'];
$display_string .= " UPDATED: ".$tag_array['updated']."
\n";

$display_string .= "


\n";

return $display_string;
}

function display_as_user ( &$tag_array ) {

global $base_feed_url;

$display_string = "";
$display_string .= "

$display_string .= "
\n";

$display_string .= "<img src=\"".$tag_array['media:thumbnail_url']['media:thumbnail_url'][0]."\"";
$display_string .= " border=\"0\" alt=\"".$tag_array['title']."\">\n";

$display_string .= "
\n";

$display_string .= "TITLE: ".$tag_array['title']."";
$display_string .= " USER: ".$tag_array['name']."
\n";

if ( $tag_array['yt:description'] ) { $display_string .= "DESCRIPTION: ".$tag_array['yt:description']."
\n"; }
else { $display_string .= "DESCRIPTION:
\n"; }

$display_string .= "PUBLISHED: ".$tag_array['published'];
$display_string .= " UPDATED: ".$tag_array['updated']."
\n";

$key = $tag_array['yt:statistics_subscriberCount']['yt:statistics_subscriberCount'][0];
$display_string .= "VIEW COUNT: ".$tag_array['yt:statistics_subscriberCount']['viewCount'][$key];
$display_string .= " VIDEO WATCH COUNT: ".$tag_array['yt:statistics_subscriberCount']['videoWatchCount'][$key]."\n";
$display_string .= " SUBSCRIBER COUNT: ".$key."
\n";
$display_string .= "LAST ACCESS: ".$tag_array['yt:statistics_subscriberCount']['lastWebAccess'][$key]."\n";

$key = $tag_array['link_rel']['link_rel'][2];
if ( strstr($key, "related") ) {

$key = $tag_array['link_rel']['href'][$key];
$display_string .= " WEBSITE: ".$key."
\n";
}
else {

$display_string .= " WEBSITE:
\n";
}

$key = $tag_array['gd:feedLink_rel']['gd:feedLink_rel'][0];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['gd:feedLink_rel']['href'][$key]) or die ();
$display_string .= "FAVORITES";
$display_string .= " NO.: ".$tag_array['gd:feedLink_rel']['countHint'][$key];

$key = $tag_array['gd:feedLink_rel']['gd:feedLink_rel'][1];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['gd:feedLink_rel']['href'][$key]) or die ();
$display_string .= " CONTACTS";
$display_string .= " NO.: ".$tag_array['gd:feedLink_rel']['countHint'][$key]."
\n";

$key = $tag_array['gd:feedLink_rel']['gd:feedLink_rel'][2];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['gd:feedLink_rel']['href'][$key]) or die ();
//$display_string .= " INBOX";
$display_string .= " NO.: ".$tag_array['gd:feedLink_rel']['countHint'][$key]."
\n";

$key = $tag_array['gd:feedLink_rel']['gd:feedLink_rel'][3];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['gd:feedLink_rel']['href'][$key]) or die ();
$display_string .= "PLAYLISTS";

$key = $tag_array['gd:feedLink_rel']['gd:feedLink_rel'][4];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['gd:feedLink_rel']['href'][$key]) or die ();
$display_string .= " SUBSCRIPTIONS";
$display_string .= " NO.: ".$tag_array['gd:feedLink_rel']['countHint'][$key];

$key = $tag_array['gd:feedLink_rel']['gd:feedLink_rel'][5];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['gd:feedLink_rel']['href'][$key]) or die ();
$display_string .= " UPLOADS";
$display_string .= " NO.: ".$tag_array['gd:feedLink_rel']['countHint'][$key]."
\n";

$key = $tag_array['link_rel']['link_rel'][1];
if ( strstr($key, "featured-video") ) {

$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['link_rel']['href'][$key]) or die ();
$display_string .= "FEATURED VIDEO\n";
}

$display_string .= "









\n";

return $display_string;
}

function display_as_sub ( &$tag_array ) {

$display_string = "";
$display_string .= "

$display_string .= "
\n";

$display_string .= "TITLE:

".$tag_array['title']."

";

$display_string .= " USER: ".$tag_array['yt:username']."\n";

$key = $tag_array['gd:feedLink_rel']['gd:feedLink_rel'][0];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['gd:feedLink_rel']['href'][$key]) or die ();
$display_string .= " UPLOADS";
$display_string .= " NO.: ".$tag_array['gd:feedLink_rel']['countHint'][$key]."
\n";

$display_string .= "PUBLISHED: ".$tag_array['published'];
$display_string .= " UPDATED: ".$tag_array['updated']."
\n";

$display_string .= "

\n";

return $display_string;
}

function display_as_contact ( &$tag_array ) {

$display_string = "";
$display_string .= "

$display_string .= "
\n";

$display_string .= "TITLE:

".$tag_array['title']."

";

$display_string .= " USER: ".$tag_array['yt:username']."
\n";

$display_string .= "PUBLISHED: ".$tag_array['published'];
$display_string .= " UPDATED: ".$tag_array['updated']."
\n";

$display_string .= "

\n";

return $display_string;
}

function display_as_playlist ( &$tag_array ) {

global $base_feed_url;

$display_string = "";
$display_string .= "

$display_string .= "
\n";

$display_string .= "TITLE:

".$tag_array['title']."

";

$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['uri']) or die();
$display_string .= " USER: ".$tag_array['name']."
\n";

$display_string .= "DESCRIPTION: ".$tag_array['yt:description']."
\n";

$display_string .= "PUBLISHED: ".$tag_array['published'];
$display_string .= " UPDATED: ".$tag_array['updated']."
\n";

$key = $tag_array['gd:feedLink_rel']['gd:feedLink_rel'][0];
$url_pass = preg_replace('/'.$base_feed_url.'/', '', $tag_array['gd:feedLink_rel']['href'][$key]) or die ();
$display_string .= "PLAYLIST";
$display_string .= " NO.: ".$tag_array['gd:feedLink_rel']['countHint'][$key]."
\n";

$display_string .= "



\n";

return $display_string;
}

function encode_ord ( $encode_string ) {

$ord_string = "";
$char_array = preg_split("//", $encode_string);

foreach ( $char_array as $ca_value ) {

$ord_string .= ord( $ca_value ).".";
}

$ord_string = preg_replace('/\.$/', '', $ord_string);
$ord_string = preg_replace('/\.0$/', '', $ord_string);
$ord_string = preg_replace('/^0\./', '', $ord_string);

return $ord_string;
}

function make_path ( $make_dir_string ) {

global $max_files_directory;

$divider_count = 1;
$unpack_count = 0;
$mds_length = strlen( $make_dir_string );
$return_dir_path = "";

while ( $unpack_count < $mds_length ) {

$return_dir_path .= substr($make_dir_string, $unpack_count, 1);
$unpack_count++;

if ( $divider_count == ( strlen($max_files_directory) - 1 ) ) {

$return_dir_path .= "/";
$divider_count = 0;
}

$divider_count++;
}

$return_dir_path = preg_replace('/\/$/', '', $return_dir_path);
return $return_dir_path;
}

function folder_create ( $folder_create_path, $folder2create, $folder_perm ) {

$folder2create = explode("/", $folder2create) or die();
array_pop($folder2create) or die();

foreach ( $folder2create as $f2c ) {

$folder_create_path .= "/$f2c" or die();

if ( ! is_dir($folder_create_path) ) {

mkdir($folder_create_path, $folder_perm) or die ();
chmod($folder_create_path, $folder_perm);
}
}
}

?>

<html>
<head>
<title></title>
<META content="all" name="robots">
<META content="follow" name="robots">
<META content="" name="description">
<META content="" name="keywords">

<script type="text/javascript">

( document.getElementById ) ? dom = true : dom = false;
var browser_name = navigator.appName;
var layer_set = 0;

function hideIt() {

document.getElementById('player').style.visibility = 'hidden';
document.getElementById('playercode').innerHTML = ' ';
layer_set = 0;
}

function showIt() {

getScroll();

document.getElementById('player').style.top = scrOfY + 30 + 'px';
document.getElementById('player').style.left = scrOfX + 'px';
document.getElementById('player').style.visibility = 'visible';
layer_set = 1;
}

function resizeIt ( resize_width , resize_height ) {

width_unit = "px";
height_unit = "px";

if ( resize_width == 0 ) { resize_width = 100; width_unit = "%"; }
if ( resize_height == 0 ) { resize_height = 100; height_unit = "%"; }

document.getElementById('player').style.width = resize_width + width_unit;
document.getElementById('player').style.height = resize_height + height_unit;
}

function writeIt () {

document.write('

');
}

function decode_chr ( encode_string ) {

var ord = encode_string.split(".");
var chars = new Array();

for ( var i=0; i < ord.length; ++i ) { chars.push( String.fromCharCode(ord[i]) ); }

var chr_string = chars.join("");

return chr_string;
}

function startPlayer ( titleSP , video_removedSP ) {

if ( dom ) {

title = decode_chr(titleSP);
video_removed = decode_chr(video_removedSP);

var player_code = "
To move this Videoplayer Window, first click inside this Area,
then click anywhere in the Document to move the Window to the Click Position,
repeat for another Move.

\n";

player_code += 'Playing " '+title+' "

\n';

player_code += '<object width="200" height="200"><param name="movie" value="';<br mode=" hold=" /> player_code += video_url;<br mode=" /><param name="wmode" value="transparent" /><embed src="';
player_code += video_url;
player_code += '"type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>\n\n';

showIt();
document.getElementById('playercode').innerHTML = player_code;
}
}

function getScroll () {

scrOfX = 0;
scrOfY = 0;

if( typeof( window.pageYOffset ) == 'number' ) {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
}
else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
}
else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}
}

function Mausklick (Ereignis) {

if (!Ereignis) Ereignis = window.event;
getScroll();

if (document.getElementById) {
document.getElementById("player").style.left = Ereignis.clientX + scrOfX + "px";
document.getElementById("player").style.top = Ereignis.clientY + scrOfY + "px";
} else if (document.all) {
document.all.player.style.left = Ereignis.clientX + scrOfX + "px";
document.all.player.style.top = Ereignis.clientY + scrOfY + "px";
}

document.onmousedown = "";
}

function register () { document.onmousedown = Mausklick; }

writeIt();
</script>

<style>

span.tags { color: #DC2B19 }
</style>

<script type="text/javascript"></script>
<script src="../js/jquery-1.9.1.js"></script>
</head>

<body bgcolor=FFFFFF>
<!--


Order by<select name="orderby">
<option>relevance</option>
<option>published</option>
<option>Rating</option>
<option>Viewcount</option>
</select>
<input type="hidden" name="search" value="1">
<input type="button" id="search" value="Search">



-->
<left>

print '';
if ( !$header_image ) { print "".$title."

\n"; }
else { print '<img src="'.$header_image.'" border=0>

\n'; }
?>




Back to the Top | Powered by Youtube



<script>
jQuery(document).ready(function()
{
jQuery.ajax(
{
type: 'GET',
url: 'category.php',
dataType: 'JSON',
success:function(data)
{
for(i=0;i<jquery(data).length;i++)>
{
$('#parentCategory').append('<option value = '+ data[i].category_name+'>' + data[i].category_name + '</option>');
}
}
});
});
</script>

<script>
jQuery(document).ready(function()
{
jQuery('#parentCategory').change(function()
{
jQuery("#subCategory").load("subcategory.php?choice="+jQuery("#parentCategory").val());
});
});
</script>

<script>

jQuery(document).ready(function()
{

jQuery('#submit').click(function()
{
var videoDetails =[];
jQuery('.mycheckbox').each(function()
{
if (this.checked == true)
{
var obj = {};

obj.thumbnailImage =jQuery (this).parent(). find('table').find ('tbody').find('tr').find('td:first').find('img').prop("src");
obj.title=jQuery(this).parent() .find('table').find('tbody').find('tr') .find('td:nth(1)').find('p:nth(0)').html();
obj.category=jQuery(this).parent().find('table') .find('tbody').find ('tr').find('td:nth(1)').find('p:nth(1)').html();
obj.description=jQuery(this). parent().find('table'). find('tbody'). find('tr').find('td:nth(1)').find('p:nth(2)').html();
obj.videoLink=jQuery(this).parent(). find('table').find('tbody').find ('tr').find('td:nth(1)').find('p:nth(3)').find('a').prop("href");

videoDetails.push(obj);

//alert(videoDetails);
}
});
//var jsonString = {array: videoDetails}JSON.stringify(videoDetails);
var jsonString = JSON.stringify(videoDetails);
//alert(jsonString);
jQuery.ajax(
{
type: 'POST',
url: 'result.php',
data: JSON.stringify({ 'videoDetailsData': jsonString }),
success: function(data)
{
if(data=="success")
{
alert("Data stored successfully");
}
},
error: function(xhr, textStatus, errorThrown)
{
alert('An error occurred! ' + ( errorThrown ? errorThrown :xhr.status));
}
});
//jQuery.post('result.php',{data:jsonString},function(data){alert(data);}{'videoDetailsData': jsonString});

});

});
</script>

<form id="testform" method="POST" action="">

<select id="parentCategory" value="parentCategory" name="category">
<option selected="selected" name="category" value="selected">--Select category--</option>
</select>






<select id="subCategory" name="subCategory">
<option selected="selected" name="subCategory" value="selected">--Select subCategory--</option>
</select>






<input type="button" id="submit" value="save"/>





</form>
</body>
</html>




<!--<input type="checkbox" name="check">-->
?>

Posted
Updated 19-Feb-14 3:02am
v6
Comments
Janardhanam Julapalli 18-Feb-14 5:47am    
please can anyone help me out?
Kornfeld Eliyahu Peter 18-Feb-14 5:49am    
Can yo format your code - it's hard to read! (use Improve question button)
Janardhanam Julapalli 18-Feb-14 5:53am    
Janardhanam Julapalli 18-Feb-14 5:53am    
this is my php code
Kornfeld Eliyahu Peter 18-Feb-14 5:56am    
Good! Now use code formatting so we can read it!

What you are creating in JQuery is a one dimensional array from all selected values...
Like:
[
thumbnailImage1,title1,category1,description1,videoLink1,
thumbnailImage2,title2,category2,description2,videoLink2,
...,
thumbnailImagen,titlen,categoryn,descriptionn,videoLinkn
]

Try to create an array of objects...
Like:
[
{thumbnailImage1,title1,category1,description1,videoLink1},
{thumbnailImage2,title2,category2,description2,videoLink2},
...,
{thumbnailImagen,titlen,categoryn,descriptionn,videoLinkn}
]

Use code like this
JavaScript
var obj = {};

obj.thumbnailImage =jQuery (this).parent(). find('table').find ('tbody').find('tr').find('td:first').find('img').prop("src");
obj.title=jQuery(this).parent() .find('table').find('tbody').find('tr') .find('td:nth(1)').find('p:nth(0)').html();
obj.category=jQuery(this).parent().find('table') .find('tbody').find ('tr').find('td:nth(1)').find('p:nth(1)').html();
obj.description=jQuery(this). parent().find('table'). find('tbody'). find('tr').find('td:nth(1)').find('p:nth(2)').html();
obj.videoLink=jQuery(this).parent(). find('table').find('tbody').find ('tr').find('td:nth(1)').find('p:nth(3)').find('a').prop("href");

videoDetails.push(obj);

In PHP you will get an object array and for each will work perfectly on it...

UPDATE...

index.php
HTML
<html>
<head>
<title>CP_Test</title>

<script
	src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>

<body>
	<input type="button" onclick="goServer();" value="Go">

	<script type="text/javascript">
			function goServer()
			{
				var arr = [];
				var obj1 = {};
				var obj2 = {};
				var obj3 = {};

				obj1.val1 = 'val1_1';
				obj1.val2 = 'val1_2';
				obj1.val3 = 'val1_3';

				obj2.val1 = 'val2_1';
				obj2.val2 = 'val2_2';
				obj2.val3 = 'val2_3';

				obj3.val1 = 'val3_1';
				obj3.val2 = 'val3_2';
				obj3.val3 = 'val3_3';
				
				arr.push(obj1);
				arr.push(obj2);
				arr.push(obj3);

				$.ajax({
			        type: 'post',
					url: 'go.php',
			        data: {json: JSON.stringify(arr)},
		         	success: function(data, textStatus, jqXHR) {
                    	alert(textStatus);
					},
					error: function(jqXHR, textStatus, errorThrown)
					{
						alert(textStatus);
					}
				});
			}
		</script>
</body>
</html>

go.php
PHP
<?php
 $json = $_POST['json'];
 
 $obj = json_decode($json);
 
 foreach ($obj as $el)
 {
 	$val1 = $el->val1;
 	$val2 = $el->val2;
 	$val3 = $el->val3;
 	
 	// save
 }
 ?>
 
Share this answer
 
v2
Comments
Janardhanam Julapalli 18-Feb-14 7:24am    
The above code is working fine.
Can i use foreach like this: foreach($videoDetails as $value)
and where should i use it?Please help me out
Kornfeld Eliyahu Peter 18-Feb-14 7:30am    
$videoDetailsData = json_decode($_POST['videoDetailsData']);

foreach($videoDetailsData as $videoDetails)
{
$thumbnailImage = mysql_real_escape_string($videoDetails.thumbnailImage);
$title = mysql_real_escape_string($videoDetails.title );
$category = mysql_real_escape_string($videoDetails.category );
$description = mysql_real_escape_string($videoDetails.description );
$videoLink = mysql_real_escape_string($videoDetails.videoLink );

$result = mysql_query("INSERT into videoDetails(thumbnailImage,title,category,description,videoLink) values('$thumbnailImage','$title','$category','$description','$videoLink')");
}
Janardhanam Julapalli 18-Feb-14 7:45am    
its not working.An error occurred! Internal Server Error.This is the error.
Kornfeld Eliyahu Peter 18-Feb-14 7:48am    
At which point?
Janardhanam Julapalli 18-Feb-14 7:52am    
In console i can see the values but not inserted into DB.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900