Friday, 14 October 2011
Convert Varchar to Date Format in mysql
SELECT * FROM `tMembers` where str_to_date(sBirthDay,"%m/%d/%Y") between str_to_date('12/15/1985',"%m/%d/%Y") and str_to_date('09/22/1987',"%m/%d/%Y")
Wednesday, 7 September 2011
Youtube API(Upload video to our website)
First, download Zend Framework......
<?php
//debug
#error_reporting(E_ALL);
//include Zend Gdata Libs
require_once("Zend/Gdata/ClientLogin.php");
require_once("Zend/Gdata/HttpClient.php");
require_once("Zend/Gdata/YouTube.php");
require_once("Zend/Gdata/App/MediaFileSource.php");
require_once("Zend/Gdata/App/HttpException.php");
require_once('Zend/Uri/Http.php');
//yt account info
$yt_user = ' '; //youtube username or gmail account
$yt_pw = ' '; //account password
$yt_source = 'jh'; //name of application (can be anything)
//video path
$video_url = '1.mov';
//yt dev key
$yt_api_key = 'AI39s...'; //your youtube developer key
//login in to YT
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $yt_user,
$password = $yt_pw,
$service = 'youtube',
$client = null,
$source = $yt_source, // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource($video_url);
$filesource->setContentType('video/quicktime'); //make sure to set the proper content type.
$filesource->setSlug('1.mov');
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle('name');
$myVideoEntry->setVideoDescription('desc');
// Note that category must be a valid YouTube category !
$myVideoEntry->setVideoCategory('Comedy');
// Set keywords, note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry->SetVideoTags('cars, funny');
// Upload URI for the currently authenticated user
$uploadUrl = "http://uploads.gdata.youtube.com/feeds/users/$yt_user/uploads";
// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if availableor just a regular Zend_Gdata_App_Exception
try {
$newEntry = $yt->insertEntry($myVideoEntry,
$uploadUrl,
'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
//this outputs a ton of garbage. not sure what to do with it yet.
/*echo "
";
echo "
";*/
$state = $newEntry->getVideoState();
if ($state) {
ehco 'Upload status for video ID ' . $newEntry->getVideoId() . ' is ' .
$state->getName() . ' - ' . $state->getText() . "\n";
} else {
echo "Not able to retrieve the video status information yet. " .
"Please try again later.\n";
}
?>
<?php
//debug
#error_reporting(E_ALL);
//include Zend Gdata Libs
require_once("Zend/Gdata/ClientLogin.php");
require_once("Zend/Gdata/HttpClient.php");
require_once("Zend/Gdata/YouTube.php");
require_once("Zend/Gdata/App/MediaFileSource.php");
require_once("Zend/Gdata/App/HttpException.php");
require_once('Zend/Uri/Http.php');
//yt account info
$yt_user = ' '; //youtube username or gmail account
$yt_pw = ' '; //account password
$yt_source = 'jh'; //name of application (can be anything)
//video path
$video_url = '1.mov';
//yt dev key
$yt_api_key = 'AI39s...'; //your youtube developer key
//login in to YT
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $yt_user,
$password = $yt_pw,
$service = 'youtube',
$client = null,
$source = $yt_source, // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource($video_url);
$filesource->setContentType('video/quicktime'); //make sure to set the proper content type.
$filesource->setSlug('1.mov');
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle('name');
$myVideoEntry->setVideoDescription('desc');
// Note that category must be a valid YouTube category !
$myVideoEntry->setVideoCategory('Comedy');
// Set keywords, note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry->SetVideoTags('cars, funny');
// Upload URI for the currently authenticated user
$uploadUrl = "http://uploads.gdata.youtube.com/feeds/users/$yt_user/uploads";
// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if availableor just a regular Zend_Gdata_App_Exception
try {
$newEntry = $yt->insertEntry($myVideoEntry,
$uploadUrl,
'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
//this outputs a ton of garbage. not sure what to do with it yet.
/*echo "
" . var_dump($newEntry) . "
";
echo "
";*/
$state = $newEntry->getVideoState();
if ($state) {
ehco 'Upload status for video ID ' . $newEntry->getVideoId() . ' is ' .
$state->getName() . ' - ' . $state->getText() . "\n";
} else {
echo "Not able to retrieve the video status information yet. " .
"Please try again later.\n";
}
?>
Friday, 19 August 2011
Display data dynamically in Matrix format using PHP with pagination
<?php
$per_page = 6;
$display_columns = 3;
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$pages = implode(mysql_fetch_assoc(mysql_query("SELECT COUNT(*) FROM projects")));
//$pages= $pages/$display_columns;
$pages = ceil($pages / $per_page);
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") $querystring .= "$key=$value&";
}
echo "Pages: ";
for ($i = 1; $i <= $pages; $i++) {
echo "<a " . ($i == $page ? "class=\"selected\" " : "");
echo "href=\"?{$querystring}page=$i";
echo "\">$i</a> ";
}
$i="";
$sqlm="select * from projects LIMIT " . (($page - 1) * $per_page) . ", $per_page";
$rsm=mysql_query($sqlm) or die("Database Error".mysql_error());
$count = mysql_num_rows($rsm);
$padding = ($display_columns-1)-(($count-1)%$display_columns);
echo '<table cellpadding=10>';
while($row=mysql_fetch_array($rsm))
{
if($i%$display_columns == 0)
echo '<tr>';
echo '<td>';
$id=$row["id"];
$in_sql="select * from projects where id=$id";
$r=mysql_query($in_sql) or die("Database Error".mysql_error());
if($rw=mysql_fetch_array($r))
{
$image=$rw['img'];
}
?>
<td>
<img src="admin/pages/Upload/<?=$image; ?>" width="160" height="160" style="border:#999;border:double"><br />
<h4><a href="projects_view.php?id=<?=$id?>"><?=$rw['title'];?></a></h4><h4 align="center"><?=$rw['cat_id'];?></h4>
</td>
<?
echo '</td>';
if($i%$display_columns == $display_columns-1)
echo '</tr>';
$i++;
}
if($padding!=0)
{
for($i=0;$i<$padding;$i++)
echo '<td></td>';
echo '</tr>';
}
echo '</table>';
?>
$per_page = 6;
$display_columns = 3;
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$pages = implode(mysql_fetch_assoc(mysql_query("SELECT COUNT(*) FROM projects")));
//$pages= $pages/$display_columns;
$pages = ceil($pages / $per_page);
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") $querystring .= "$key=$value&";
}
echo "Pages: ";
for ($i = 1; $i <= $pages; $i++) {
echo "<a " . ($i == $page ? "class=\"selected\" " : "");
echo "href=\"?{$querystring}page=$i";
echo "\">$i</a> ";
}
$i="";
$sqlm="select * from projects LIMIT " . (($page - 1) * $per_page) . ", $per_page";
$rsm=mysql_query($sqlm) or die("Database Error".mysql_error());
$count = mysql_num_rows($rsm);
$padding = ($display_columns-1)-(($count-1)%$display_columns);
echo '<table cellpadding=10>';
while($row=mysql_fetch_array($rsm))
{
if($i%$display_columns == 0)
echo '<tr>';
echo '<td>';
$id=$row["id"];
$in_sql="select * from projects where id=$id";
$r=mysql_query($in_sql) or die("Database Error".mysql_error());
if($rw=mysql_fetch_array($r))
{
$image=$rw['img'];
}
?>
<td>
<img src="admin/pages/Upload/<?=$image; ?>" width="160" height="160" style="border:#999;border:double"><br />
<h4><a href="projects_view.php?id=<?=$id?>"><?=$rw['title'];?></a></h4><h4 align="center"><?=$rw['cat_id'];?></h4>
</td>
<?
echo '</td>';
if($i%$display_columns == $display_columns-1)
echo '</tr>';
$i++;
}
if($padding!=0)
{
for($i=0;$i<$padding;$i++)
echo '<td></td>';
echo '</tr>';
}
echo '</table>';
?>
Tuesday, 19 July 2011
VB.NET Connection String
Imports System.Data.OleDb
Public Class Form1
Dim connetionString As String
Dim conn As OleDbConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\USER\Documents\Database3.accdb"
conn = New OleDbConnection(connetionString)
Try
conn.Open()
MsgBox("Done")
conn.Close()
Catch ex As Exception
MsgBox("Not Done")
End Try
End Sub
End Class
Public Class Form1
Dim connetionString As String
Dim conn As OleDbConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\USER\Documents\Database3.accdb"
conn = New OleDbConnection(connetionString)
Try
conn.Open()
MsgBox("Done")
conn.Close()
Catch ex As Exception
MsgBox("Not Done")
End Try
End Sub
End Class
Saturday, 16 July 2011
PHP: Mail with HTML and mail() function.
<?php
include ("include/config.php");
$fname=$_POST['name'];
$email="From:".$_POST['email'];
$comp=$_POST['company'];
$msg1=$_POST['message'];
$tomail="swapn_developers@yahoo.com";
$msg="Company Name : " .$comp."
"."Message : " .$msg1;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
mail($tomail,"Contact Us Message",$msg,$headers);
?>
include ("include/config.php");
$fname=$_POST['name'];
$email="From:".$_POST['email'];
$comp=$_POST['company'];
$msg1=$_POST['message'];
$tomail="swapn_developers@yahoo.com";
$msg="Company Name : " .$comp."
"."Message : " .$msg1;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
mail($tomail,"Contact Us Message",$msg,$headers);
?>
How to Download Image , txt file or any file without save as or without open in php?
<?php
$file=$_GET['file'];//get the file name
//$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
$file=$_GET['file'];//get the file name
//$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
Friday, 15 July 2011
AJAX-Passing the multiple value to another page.
function searchDoc1(str,str1)
{
if (str=="")
{
document.getElementById("list").innerHTML="";
return;
}
if (str1=="")
{
document.getElementById("list").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//alert(xmlhttp.responseText);
document.getElementById("list").innerHTML=xmlhttp.responseText;
}
else if(xmlhttp.readyState==3)//waiting Module
{
document.getElementById("list").innerHTML = "waiting";// or "using the image tag to display image"
}
}
var url1="list_out.php"
url=url1+"?q1="+str+"&q2="+str1
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
{
if (str=="")
{
document.getElementById("list").innerHTML="";
return;
}
if (str1=="")
{
document.getElementById("list").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//alert(xmlhttp.responseText);
document.getElementById("list").innerHTML=xmlhttp.responseText;
}
else if(xmlhttp.readyState==3)//waiting Module
{
document.getElementById("list").innerHTML = "waiting";// or "using the image tag to display image"
}
}
var url1="list_out.php"
url=url1+"?q1="+str+"&q2="+str1
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
Subscribe to:
Posts (Atom)