PHP Tips-Getting the nodes list of xml doument with responseXml in ajax ,call image save in database,time difference etc
Getting the nodes list of xml doument with responseXml in ajax
var obj = "";
function callAjaxObj()
{
try
{
obj = new XMLHttpRequest();
}
catch(e)
{
try
{
obj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
obj = ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("your browser doesn't support ajax");
return false;
}
}
}
}
function testResponseXml()
{
callAjaxObj();
obj.open("get","sample.xml",true);
obj.onreadystatechange=function()
{
if(obj.readyState==4)
{
var doc = obj.responseXML.documentElement;
//var doc = obj.responseXML;
alert(doc.getElementsByTagName('user').length);
}
}
obj.send(null);
}
Example of calender script in PHPcalender script in PHP
echo " $title $year ";
echo "SMTWTFS";
$day_count = 1;
echo "";
while ( $blank > 0 )
{
echo "";
$blank = $blank-1;
$day_count++;
}
$day_num = 1;
while ( $day_num <= $days_in_month )
{
echo " $day_num ";
$day_num++;
$day_count++;
if ($day_count > 7)
{
echo "";
$day_count = 1;
}
}
while ( $day_count >1 && $day_count <=7 )
{
echo " ";
$day_count++;
}
echo "";
PHP code for finding time difference $h1 = substr($time1,0,2);
$h2 = substr($time2,0,2);
$m1 = substr($time1,3,2);
$m2 = substr($time2,3,2);
$s1 = substr($time1,6,2);
$s2 = substr($time2,6,2);
if($s1 > $s2)
{
$m1 = $m1 - 1;
$s1 = $s1 + 60;
}
else
{
$m1 = $m1;
$s1 = $s1;
}
if($m1 > $m2)
{
$h1 = $h1 - 1;
$m1 = $m1 + 60;
}
else
{
$h1 = $h1;
$m1 = $m1;
}
$h = $h2 - $h1;if($h <= 9)$h = "0".$h;
$m = $m2 - $m1;if($m <= 9)$m = "0".$m;
$s = $s2 - $s1;if($s <= 9)$s = "0".$s;
echo $h.":".$m.":".$s;echo "
";
How to call image save in database using php?
$image_query=mysql_query("select images from tablename");
while($image_data=mysql_fetch_array($image_query))
{
echo $image_data['images'];
}
This will display all the images that you stored in the table.