Wednesday, May 30, 2007

Integrate DATE AND TIME PICKER to textbox


<script language = 'javascript' src = 'datetimepicker.js'></script>


<tr>

<td width="15%">&nbsp;</td>

<Td width="20%" class="content_font">Date</td>

<td >

<input type="text" id="date" size=25 name="date" class="content_font" readonly>&nbsp;

<a href="javascript:NewCal('date','yyyymmdd',true,24)" class="content_font"><img src='../images/cal.gif' border='0'></a>



</td>

</tr>


above date and time picker script is u can download from this site

http://www.rainforestnet.com/download/mydatetimepicker/sample.zip

and intigrated as given above and look like that

Friday, May 25, 2007

Read xml file using simplexml functions in PHP

first you have to create xml file


<ReportData>

<Record>

<CCode>client 2</CCode>

<DESTINATION>USA</DESTINATION>

<AIRWAYBILL>A222</AIRWAYBILL>

<AWB>AQ222</AWB>

<SUB>

<DATE>5/21/2007</DATE>

<TIME>12:24:04 PM</TIME>

</SUB>

</Record>



<Record>

<CCode>client 2</CCode>

<DESTINATION>USA</DESTINATION>

<AIRWAYBILL>A222</AIRWAYBILL>

<AWB>AQ222</AWB>

<SUB>

<DATE>5/21/2007</DATE>

<TIME>12:24:04 PM</TIME>

</SUB>

</Record>



<Record>

<CCode>client 2</CCode>

<DESTINATION>USA</DESTINATION>

<AIRWAYBILL>A222</AIRWAYBILL>

<AWB>AQ222</AWB>

<SUB>

<DATE>5/21/2007</DATE>

<TIME>12:24:04 PM</TIME>

</SUB>

</Record>

</ReportData>


now user this code for parsing read in with simplexml functions


 


if(!$xml=simplexml_load_file('report.xml'))

{

trigger_error('Error reading XML file',E_USER_ERROR);

echo "file loaded";

}

echo 'Displaying contents of XML file...<br />';

foreach($xml as $records){

echo '<B>CLINET CODE: </b>'.$records->CCode.'<B> DESTINATION: <b>'.$records->DESTINATION.'

<B>AIRWAY BILL: </b>'.$records->AIRWAYBILL.'<br />';

}


run it this will display result of cccode and destination and airwaybill

Tuesday, May 22, 2007

Read xml file using DOM in PHP

<ReportData>

<Record>

<CCode>client 2</CCode>

<DESTINATION>USA</DESTINATION>

<AIRWAYBILL>A222</AIRWAYBILL>

<AWB>AQ222</AWB>

<SUB>

<DATE>5/21/2007</DATE>

<TIME>12:24:04 PM</TIME>

</SUB>

</Record>

</ReportData>


save above as report.xml file and than


run below script its script using dom how


you can read data from an xml file


 


<?php

$doc = new DOMDocument();

$doc->load( 'report.xml' );



$Record = $doc->getElementsByTagName( "Record" );

foreach( $Record as $rec )

{

$ccode = $rec->getElementsByTagName( "CCode" );

$ccode= $ccode->item(0)->nodeValue;



$destination = $rec->getElementsByTagName("DESTINATION");

$destination = $destination->item(0)->nodeValue;



$airwaybill = $rec->getElementsByTagName("AIRWAYBILL");

$airwaybill = $airwaybill->item(0)->nodeValue;



$awb = $rec->getElementsByTagName("AWB");

$awb = $awb->item(0)->nodeValue;



$SUB = $rec->getElementsByTagName( "SUB" );

$SUB = $SUB->item(0)->nodeValue;





$date = $rec->getElementsByTagName( "DATE" );

$date = $date->item(0)->nodeValue;

$time = $rec->getElementsByTagName( "TIME" );

$time = $time->item(0)->nodeValue;



echo "$ccode - $destination - $airwaybill - $awb - $SUB - $date - $time <BR>";

}

?>

Monday, May 21, 2007

connect with ms-access and print the table of data in php

<?php

$db_conn = new COM("ADODB.Connection");

$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("thedata.mdb").";";

$db_conn->open($connstr);

if($db_conn)

{

echo "connected";

}

else

{

echo "not conected";

}

$rS = $db_conn->execute("SELECT * FROM main1");


$cnt=0;

echo"<table>";

while (!$rS->EOF)

{



if($cnt%2 == 0 )

{

print "<tr bgcolor='#C0C0C0'><td>".$rS->Fields(0)."</td><td>". $rS->Fields(1)."</td><td>".$rS->Fields(2)."</td><td>".$rS->Fields(3)."</td><td>".$rS->Fields(4)."</td><td> ".$rS->Fields(5)."</td><td>".$rS->Fields(6)."</td></tr>\n";

}

else

{

print "<tr><td>".$rS->Fields(0)."</td><td>". $rS->Fields(1)."</td><td>".$rS->Fields(2)."</td><td>".$rS->Fields(3)."</td><td>".$rS->Fields(4)."</td><td> ".$rS->Fields(5)."</td><td>".$rS->Fields(6)."</td></tr>\n";

}

$cnt++;

$rS->MoveNext();

}

echo"</table>";

$rS->Close();

$db_conn->Close();

?>



its eassy that you have to just change your database name for run this script

Tuesday, April 24, 2007

prototype.js and effects.js use in html for interface

<html>


<script type="text/javascript" src="prototype.js"></script>

<script type="text/javascript" src="effects.js"></script>

<head>

<title>kaal made for you</title>


</head>

<body onLoad="javascript:new Effect.Fade('search');">


<p id="deleted-text">Here is some important text, it will be highlighted

when the page loads.</p>


<script type="text/javascript">

new Effect.Fade("deleted-text", {duration:4.0});

</script>


<form id="search" action='' method='post'>

<input type='text' size=20>

<input type='Submit' value='search' name='search'>

</form>

<BR>


<a href='#'

onClick="javascript:new Effect.Fade('search');">Hide</a>

&nbsp;|&nbsp;

<a href='#'

onClick="javascript:new Effect.Appear('search');">Search</a>


</body>

</html>

Send Mail using PHP mail() function with Html Content

<?php


$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers

$headers .= 'From: Kals[sender] <krakholiya@gmail.com>' . "\r\n";

// Mail it

$sendx = mail($to, $subject, $content, $headers);


if( $sendx )

{



echo "<font color='red'>Mail Sended.</font>";



}

else

{

$message = "Not Sended. please try again.";

}


?>

upload images in PHP

<body>

<br>

<?php

include("../db_connection_xcart.php");


if($_POST['submit'])

{

$sql = "SELECT image_id FROM `xcart_products_images` ORDER BY `image_id` DESC";

$result = mysql_query($sql);

$num = mysql_num_rows($result);

$row = mysql_fetch_array($result);

if($num)

{

$image_id = $row['image_id'];





}

else

{

$image_id = "1_x";

}





$productid = $_POST['productid'];

$image_name = $image_id."_".$_FILES['location']['name'];

$location = "../images/T/".$image_name;

if(move_uploaded_file($_FILES['location']['tmp_name'], $location))

{



$insert = "insert into xcart_products_images values('null','".$_POST['productid']."','".$image_name."')";

mysql_query($insert);

echo "<div align='center'><font color='#00FF00'>File is successfully uploaded.</font></div>\n";





}

else

{

echo "Possible file upload attack!\n";

}

if($result = mysql_query($query_insert))

{

echo"<div align='center'><font color='#00FF00'>Added Succesfully</font></div>";

}

}

?>






<br>

<div align="center">

<table bgcolor="#FFFFFF" border="0"><form name="images" action="<?php $_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">

<tr>

<td height="66" colspan="2" class="sectionheading" align="center"><b>ADD Multiple images</b></td>

</tr>

<tr>



<td height="26" align="left">

<b>product id :&nbsp;</b>

<?php



$query = "SELECT productid , product FROM xcart_products";

$product= mysql_query($query);

echo "<select name='productid' >";



while ($row = mysql_fetch_array($product))

{



echo "<option value='".$row[0]."'>".$row['product']."</option>";

}

echo"</select>";

?>

</tr>

<tr>

<td height="26" align="left" colspan="2">

<b>Image Location :&nbsp;</b>

<br>

<input type="file" name="location" size="40"></td>

</tr>

<tr>

<td>&nbsp; </td>

</tr>



<td align="center"><input type="button" name="close" value="Close" onClick="javascript:void(window.close())">&nbsp;&nbsp;



<input type="submit" name="submit" value="Upload Image" />

</td>

</tr></form>

</table>

</div>

</body>

Ajax select category and subcategory list automatic

//category.php


<script language = 'javascript'>

// create ajax instance

function GetXMLHttpRequest()

{

var object = null;



if (window.XMLHttpRequest) //for mozilla,safari,opera,nets..

{

object = new XMLHttpRequest();

}

else if (window.ActiveXObject) //for IE..

{

try

{

object = new ActiveXObject("Msxml2.XMLHTTP");

}

catch(e)

{

}



if (object == null)

{

try

{

object = new ActiveXObject("Microsoft.XMLHTTP");

}

catch(e)

{

}

}

}



if (object == null)

{

alert("Your browser does not support AJAX");

}



return object;

}

var httpxx = GetXMLHttpRequest();


//Ajax for Subcategories


 


var url_cat = "getsubcategory.php?cid=";


// handling ajax response

function handleHttpResponse2()

{

if (httpx.readyState == 4)

{



if(httpx.status == 200)

{



document.getElementById('prepage2').style.visibility='hidden';

var results=httpx.responseText.split(",");



var oSelect1 = document.getElementById("subcategory");

oSelect1.options.length=0;



if(results[0].length==0)

{

var oOption = document.createElement("option");

oOption.value = 0;

oOption.innerHTML = "-select-";



var oSelect = document.getElementById("subcategory");

oSelect.appendChild(oOption);

}

else

{

var oOption = document.createElement("option");

oOption.value = 0;

oOption.innerHTML = "-select-";



var oSelect = document.getElementById("subcategory");

oSelect.appendChild(oOption);

for (var d=0;d < results.length ;d++)

{

var oOption = document.createElement("option");

var dd1=results[d].split("-")

oOption.value = dd1[1];

oOption.innerHTML = dd1[0];



var oSelect = document.getElementById("subcategory");

oSelect.appendChild(oOption);

}

}

}

}

}


// make ajax request

function updateCategoryState() {

var categoryValue = document.getElementById("category").value;

httpx.open("GET", url_cat + escape(categoryValue), true);

document.getElementById('prepage2').style.visibility='visible';

httpx.onreadystatechange = handleHttpResponse2;

httpx.send(null);

}


var httpx = GetXMLHttpRequest();


</script>


//category.php file where selection is made and subcategory is updated


<td width="53%">

<select id="category" name='category' onchange="updateCategoryState();" class='welcome_text'>

<option value='0' class='welcome_text'>Select Category</option>

<?php


$query1Select = "select * from tblcategories";

$query1Result = query_select($query1Select,$nRows);

while($row = mysql_fetch_object($query1Result))

{

$categoryList.="<option value='$row->id'>$row->categoryname</option>";

}


?>

</select>


</td>


<tr>

<td class="caption" align='right' class='welcome_text'>SubCategory Name&nbsp;</td>

<td width="53%">

<select id="subcategory" name='subcategory' class='welcome_text'>

<option value='0' class='welcome_text'>Select Subcategory</option>

<?php


$query1Select = "select * from tblsubcategories";

$query1Result = query_select($query1Select,$nRows);

while($row = mysql_fetch_object($query1Result))

{

$subcategoryList.="<option value='$row->subcategoryname'>$row->subcategoryname</option>";

}


?>

</select>

<span id="prepage2" align='center' class='welcome_text'>

<font color='#FF0000'>

Loading ... ...Please wait

</font>

</span>

</td>

</tr>


 


 


//get subcategory file .php


<?php

$str="select * from tblsubcategories where categoryid=$cid";

$res=query_select($str,$conn);

$str="";

while ($fobj=mysql_fetch_object($res))

{

$str.="$fobj->subcategoryname"."-"."$fobj->id".",";

}

$str2=substr($str,0,strlen($str)-1);

echo "$str2";

?>

session register checking and redirecting pages...

logging script session is registered and than checked


<?php


if(session_is_registered ('user'))

{

session_destroy();

}

session_start();

session_name('user');


//session is registered and than checked....


session_register("reguser");

$reguser="$member_id";


?>


//check for user or webmasters.....


<?php



session_start();

if($_SESSION['reguser'])

{

$msg= "Logged in&nbsp;".$_SESSION['reguser'];

echo $msg;


exit();



}

if($_SESSION['webmaster'])

{

$msg= "Logged in Web Master Id no:".$_SESSION['webmaster'];

echo $msg;


exit();

}




?>


//redirect page by the header funtion as per user category


<?php


session_destroy();

if(session_is_registered('reguser'))

{

header("location: ./index.php");

}





if(session_is_registered('webmaster'))

{

header("location: ./index.php");

}
?>

password and email validations Java script

<script language="javascript">

function CheckSignup_new(frm)

{


if(frm.new_member_id.value.length == 0 || frm.new_member_id.value=='USER NAME')

{

alert("Please enter Username!");

frm.new_member_id.focus();

return false;

}

if(frm.password.value.length == 0 || frm.password.value=='PASSWORD')

{

alert("Please enter Password!");

frm.password.focus();

return false;

}

if(frm.repassword.value.length == 0 || frm.repassword.value=='PASSWORD')

{

alert("Please enter Confirm Password!");

frm.repassword.focus();

return false;

}





var re = /^(([^<>()[\]\\.,;:\s@\"]+
(\.[^<>()[\]\\.,;:\s@\"]+)*)|
(\".+\"))@
((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])
|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/





if (!frm.email.value.match(re))

{

alert("Please enter valid Email!");

frm.email.focus();

return false;

}



if(frm.email.value.length == 0 || frm.email.value=='EMAIL')

{

alert("Please enter your email!");

frm.email.focus();

return false;

}







if(frm.password.value !=frm.repassword.value)

{

alert("Cofirm password is wrong\n please retype?");

frm.repassword.focus();

return false;

}

return true;

}

</script>


this submit button within the form tag...


<input type="submit" name="signup" value="signup" onClick='return CheckSignup_new(this.form);'>

java script validation

//java script

function CheckFields(frm)
{

if(frm.sitename.value == 0)
{
alert("Please Enter site name!");
frm.sitename.focus();
return false;
}
if(frm.siteurl.value == 0)
{
alert("Please Enter site url!");
frm.siteurl.focus();
return false;
}

if (frm.discription.value.length == 0)
{
alert("Please enter site discription!");
frm.discription.focus();
return false;
}

}

//callling function by click on this button

<input type="submit" name="Submit" value="Submit" onClick='return CheckFields(this.form);'>

Wednesday, April 18, 2007

Sequence of gems to be install After ruby


1. activesupport
2. actionpack
3. activerecord
4. actionwebservice
5. actionmailer
6. rails

always install packages in this order of rails

for more details of installing ruby you can visit

http://apacheguide.org/ruby.php
all settings are mentioned here

Monday, April 16, 2007

How to treat table as data grid in the PHP

if(session_is_registered("admin"))

{

function showBookingList($sb,$m,$p,$offs,$orderstate)

{

$offset = $offs;

$querySelect = "select count(*) from tblordermanage";

$queryResult = query_select($querySelect,$nRows);

$count = mysql_result($queryResult,0,0);

$maxt = round($count/$offset,2);

$last = ceil($maxt);



if($p==1)

{

$start = 0;

$n = $p+1;

$first = "<a href=\"viewQuoted.php?page=1&orderstate=$orderstate\"><span class='w_text'><u>First</u></span></a>";

$next = "<a href=\"viewQuoted.php?page=$n&orderstate=$orderstate\"><span class='w_text'><u>Next</u></span></a>";

$previous = "<span class='caption'>Previous</span>";

$last = "<a href=\"viewQuoted.php?page=$last&orderstate=$orderstate\"><span class='w_text'><u>Last</u></span></a>";

$stp = $start+1;



if ($count==0)

{

$stp = 0;

$ltp = 0;

}

else if ($count<=$offset)

{

$ltp = $count;

$next = "<span class='caption'>Next</span>";

}

else

{

$ltp = $stp+$offset-1;

}

}

else if($p==$last)

{

$start = $p*$offset-$offset;

$pr = $p-1;

$first = "<a href=\"viewQuoted.php?page=1&orderstate=$orderstate\" class='caption'>First</a>";

$next = "<span class='caption'>Next</span>";

$previous = "<a href=\"viewQuoted.php?page=$pr&orderstate=$orderstate\" class='caption'>Previous</a>";

$last = "<a href=\"viewQuoted.php?page=$last&orderstate=$orderstate\" class='caption'>Last</a>";

$stp = $start+1;

$ltp = $count;

}

else if($p>1 and $p<$last)

{

$start = $p*$offset-$offset;

$n = $p+1;

$pr = $p-1;

$first = "<a href=\"viewQuoted.php?page=1&orderstate=$orderstate\" class='caption'>First</a>";

$next = "<a href=\"viewQuoted.php?page=$n&orderstate=$orderstate\" class='caption'>Next</a>";

$previous = "<a href=\"viewQuoted.php?page=$pr&orderstate=$orderstate\" class='caption'>Previous</a>";

$last = "<a href=\"viewQuoted.php?page=$last&orderstate=$orderstate\" class='caption'>Last</a>";

$stp = $start+1;

$ltp = $stp+$offset-1;

}





if(empty($orderstate))

{

$orderstate='Q';

}

$query1Select = "select * from tblordermanage where orderstate='".$orderstate."' and processstate='".Q."' order By arrivedate limit ". $start .",".$offset;



$query1Result = query_select($query1Select,$nRows);

$nch = 0;



if(mysql_num_rows($query1Result)>=1)

{

$str.="<tr>



<td align=\"right\">&nbsp&nbsp $first &nbsp&nbsp $previous &nbsp&nbsp $next &nbsp&nbsp $last</td>

</tr>

<tr>

<td align='left' colspan='2'>

<table border='0' width='100%'>

<tr>

<td width='22%' bgcolor='#FFFFFF' class='title' align='left'><font color='#000000'>Customer Name</font></td>

<td width='15%' bgcolor='#FFFFFF' class='title' align='center'><font color='#000000'>Arrive date</font></td>

<td width='10%' bgcolor='#FFFFFF' class='title' align='center'><font color='#000000'>Quoted</font></td>

<td width='10%' bgcolor='#FFFFFF' class='title' align='center'><font color='#000000'>Process State</font></td>



<td width='15%' bgcolor='#FFFFFF' class='title' align='center'><font color='#000000'>E-Mail</font></td>

<td width='10%' bgcolor='#FFFFFF' class='title' align='center'><font color='#000000'>Arrive Station</font></td>



</tr>";



while($arr = mysql_fetch_array($query1Result))

{

$yquery="select * from tblyear ORDER BY yid";

$yresult=query_select($yquery,$totalYearRecFound);



$cId = $arr['id'];

$name = $arr['name'];

$ostate=$arr['orderstate'];

$pstate=$arr['processstate'];



if($ostate == 'B')

{

$ostate ="Booking";

}

if($ostate == 'Q')

{

$ostate ="Quoted";

}

//$pstate=$arr['processstate'];

$arrivedate = $arr['arrivedate'];

$datearr = split("-",$arrivedate);

$year=$datearr[0];

$month=$datearr[1];

$day=$datearr[2];



$yquery="select * from tblyear where yid = $year";

$yresult=query_select($yquery,$totalYearRecFound);

$yrow=mysql_fetch_array($yresult);

$year=$yrow['caption'];

$monquery="select * from tblmonth where mid = $month";

$monresult=query_select($monquery,$totalMonRecFound);

$monrow=mysql_fetch_array($monresult);

$month=$monrow['caption'];

$adate="$year-$month-$day";

$email = $arr['email'];

$contactno = $arr['contactnumber'];

$arrivestation = $arr['arrivestation'];

$cquery = "select * from tblcity where cityid = $arrivestation";

$cresult=query_select($cquery,$totalMonRecFound);

$crow=mysql_fetch_array($cresult);

$city=$crow['caption'];



$str.="<tr>



<td class='w_text' align='center' valign='top'>$name</td>

<td class='w_text' align='center' valign='top'>$adate</td>

<td class='w_text' align='center' valign='top'>$ostate</td>

<td class='w_text' align='center' valign='top'>$pstate</td>

<td class='w_text' align='center' valign='top'><a href='mailto:$email'>

<span class='w_text'><u>$email</u></span></a></td>

<td class='w_text' align='center' valign='top'>$city</td>





</tr>";

}

$str.="</table></td></tr>";

}

else

{

$str = "

<tr>

<td valign='top' class='w_text'>There are no records !</td>

</tr>";

}

return $str;

}

if($message)

{

$message="$message";

}


if($mode == "delete" and $cid)

{

$query2Delete = "delete from tblordermanage where id=$cid";

$query2Result = query_delete($query2Delete);



if ($query2Result)

{

$message = "Order deleted successfully.";

}

}


if($page)

{

$page = $page;

}

else

{

$page = 1;

}

$bookingList = showBookingList($sortby,$mode,$page,25,$_GET['orderstate']);


this function will be sort data in both mode and and up to 25 record from table and
delete and edit opetions you can add..

Fetch data from the tables

There is Mainly Four ways to fetch data from the tables

  • mysql_fetch_array($query_result)

this function will fetch data from the query result by array you can access this array by the key which is table's field name and also by the id start with [0] and upto no. of filed in the table.

eg:

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_NUM))

{

printf("ID: %s Name: %s", $row[0], $row[1]);

// printf("ID: %s Name: %s", $row['id'], $row['name']);

}

  • mysql_fetch_object($query_result)

this function will fetch data from the query result by object you can access this object memebers bye the -> arrow operator and its key value .

$result = mysql_query("select * from mytable");

while ($row = mysql_fetch_object($result))

{

echo $row->id; echo $row->name;

}

  • mysql_fetch_row($query_result)

mysql_fetch_row( ) fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

$result = mysql_query("select * from mytable");
while ($row = mysql_fetch_row($result))
{
echo $row[0]; echo $row[1];
}

  • mysql_fetch_assoc($query_result)

Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. mysql_fetch_assoc( ) is equivalent to calling mysql_fetch_array( )with MYSQL_ASSOC for the optional second parameter. It only returns an associative array.

while ($row = mysql_fetch_assoc($result))

{

echo $row["id"]; echo $row["name"]; echo $row["user"];

}

Friday, April 13, 2007

PHP conection to Mysql database

as simple as eating chochobar.......


function mysql_dbconnect($server,$user,$pass,$db)
{
mysql_connect($server,$user,$pass);
if (!
$link) {
die(
'Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db($db, $link);
if (!
$db_selected) {
die (
'Can\'t use database : ' . mysql_error());
}

}

?>
Save above file as mysqlconnect.php you can use above function for the
any time establish mysql-php connection by including that file. and using
function you have to just call when you need

Syntax:

mysql_dbconnect('mysql serve rname','user of database','password for that user','database you wish to connect');
mysql_dbconnect('localhost','root','password','dbany');
?>