Sunday 22 November 2015

Open the webpage without click the menu use shortcut ALT+any key

<div id="cssmenu1">
 <ul>
  <li>
   <a href='WorkInProgressForm.php' accesskey="a" title="alt+a">
    <?php if(@$page=="Add New Record"){ ?>
     <span style="color:#CCFF66;"><label style="text-decoration:underline;">A</label>dd New Record</span>
<?php } else { ?>
<span><label style="text-decoration:underline">A</label>dd New Record</span>
<?php } ?>
   </a>
  </li>
  <li style="margin-left:20px;">
   <a href='workinprogresstable.php' accesskey="w" title="alt+w">
    <?php if(@$page=="Work In Progress"){ ?>
     <span style="color:#CCFF66;"><label style="text-decoration:underline">W</label>ork In Progress</span>
<?php } else { ?>
<span><label style="text-decoration:underline">W</label>ork In Progress</span>
<?php } ?>
   </a>
  </li>
  <li class='active has-sub' style="margin-left:20px;">
   <a href='report.php' accesskey="p" title="alt+p">
    <?php if(@$page=="Progress Sheet"){ ?>
     <span style="color:#CCFF66;"><label style="text-decoration:underline">P</label>rogress Sheet</span>
<?php } else { ?>
<span><label style="text-decoration:underline">P</label>rogress Sheet</span>
<?php } ?>
   </a>
  </li>
  <li class='active has-sub' style="margin-left:20px;">
   <a href='clienttable.php' accesskey="c" title="alt+c">
    <?php if(@$page=="Client Name"){ ?>
     <span style="color:#CCFF66;"><label style="text-decoration:underline">C</label>lient Name</span>
<?php } else { ?>
<span><label style="text-decoration:underline">C</label>lient Name</span>
<?php } ?>
   </a>
  </li>
  <li class='active has-sub' style="margin-left:20px;">
   <a href='task.php' accesskey="t" title="alt+t">
    <?php if(@$page=="Task Table"){ ?>
     <span style="color:#CCFF66;"><label style="text-decoration:underline">T</label>ask Table</span>
<?php } else { ?>
<span><label style="text-decoration:underline">T</label>ask Table</span>
<?php } ?>
   </a>
  </li>
  <li class='active has-sub' style="margin-left:20px;">
   <a href='assessmentyear.php' accesskey="y" title="alt+y">
    <?php if(@$page=="Assesment Year Table"){ ?>
     <span style="color:#CCFF66;">Assesment <label style="text-decoration:underline">Y</label>ear Table</span>
<?php } else { ?>
<span>Assesment <label style="text-decoration:underline">Y</label>ear Table</span>
<?php } ?>
   </a>
  </li>
  <li class='active has-sub' style="margin-left:20px;">
   <a href='StatusTB.php' accesskey="s" title="alt+s">
    <?php if(@$page=="Status"){ ?>
     <span style="color:#CCFF66;"><label style="text-decoration:underline">S</label>tatus</span>
<?php } else { ?>
<span><label style="text-decoration:underline">S</label>tatus</span>
<?php } ?>
</a>
  </li>
  <li class='active has-sub' style="margin-left:20px;">
   <a href='RemarksTB.php' accesskey="r" title="alt+r">
    <?php if(@$page=="Remarks"){ ?>
     <span style="color:#CCFF66;"><label style="text-decoration:underline">R</label>emarks</span>
<?php } else { ?>
<span><label style="text-decoration:underline">R</label>emarks</span>
<?php } ?>
</a>
  </li>
  <li class='active has-sub' style="margin-left:20px;">
   <a href='point.php' accesskey="o" title="alt+o">
    <?php if(@$page=="Work Analysis"){ ?>
     <span style="color:#CCFF66;">W<label style="text-decoration:underline">o</label>rk Analysis</span>
<?php } else { ?>
<span>W<label style="text-decoration:underline">o</label>rk Analysis</span>
<?php } ?>
</a>
  </li>

  <span style="margin-top:5px; margin-right:20px; float:right; text-align:center; font-size:17px; color:
  #00CC66;">
   Welcome <?php echo ucwords($uname[0]); ?>
  </span>
 </ul>
</div>

</div>

Tuesday 8 September 2015

Retrieve image when image present in files and image detail present in Database

  <?php
    $qry="select merchant_id,website from merchant where priority > 0 order by priority";
$top=mysql_query($qry);
while($data=mysql_fetch_assoc($top)){ ?>
<a href="http://<?php echo $data[website]; ?>" target="_blank">
<img src="/images/logo/<?php echo $data[merchant_id].'.'.'jpg' ?>" />
</a>
<?php } ?>

Monday 20 July 2015

CREATE DOWNLOADABLE CSV FILE IN PHP

CREATE DOWNLOADABLE CSV FILE IN PHP

<?php
mysql_connect('localhost','root','')
mysql_select_db('your database name');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=total_student.csv');
//to write the csv file
$output = fopen('php://output', 'w');
//heading of your file
fputcsv($output,array('Class','Total no. of students'));


for($i=1;$i<=12;$i++){
$std="select count(enrollment_no) from student_enrollment where student_curr_class_stand='$i'";
$data=mysql_fetch_array(mysql_query($std));
$class="std".$i;
$student=$data[0];
//insert data in your csv file
fputcsv($output,array($class,$student));
}

?>

Saturday 4 July 2015

insert file and image usin php and ajax

HTML AND AJAX CODE

index.php

<html>
<head>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>  
</head>
<script>
function uploadFile(){
  var input = document.getElementById("file");
  file = input.files[0];
  if(file != undefined){
    formData= new FormData();
    if(!!file.type.match(/application.*/)){
      formData.append("application", file);
      $.ajax({
        url: "upload.php",
        type: "POST",
        data: formData,
        processData: false,
        contentType: false,
        success: function(data){
            alert('success');
        }
      });
    }else{
      alert('Not a valid image!');
    }
  }else{
    alert('Input something!');
  }
}


</script>
<body>
    <input type="file" id="file" />
    <button onClick="uploadFile();">UploadFile</button>
</body>
</html>

Upload.php

<?php
$dir = "../gurukul/assignments/";
move_uploaded_file($_FILES["application"]["tmp_name"], $dir. $_FILES["application"]["name"]);
?>
INSERT DATA IN DATABASE FROM CSV OR EXCEL SHEET
 HTML CODE

<div class="admin_head"><h2>Add Data Using CSV File</h2></div>
<div class="clr"></div>
<hr />
<?php if(isset($err)) echo "<div class='error mb_15'>$err</div>"; ?>

<div class="admin_head"><h2>Upload new csv by browsing to file and clicking on Upload</h2></div>
<div class="clr"></div>

<form method="post" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" id="ad_tab">
 <tr><td></td><td></td><td></td></tr>
 <tr>
  <td class="req">File name to import : </td>
  <td><input type="file" name="filename" size="50"></td>
 </tr>
 <tr>
 <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <input type="submit" value="Upload" name="submit"></td>
 <tr>
</table>
</form>


PHP CODE

<?php
if(isset($_POST['submit'])) {
$data=$_FILES['filename'];
if(!$data['size']) $err="please select the file";
elseif(is_uploaded_file($_FILES['filename']['tmp_name'])) {
 $handle = fopen($_FILES['filename']['tmp_name'], "r");
         $hasNext=0;
 $KEY=0;
 $couponCategory=array();
 $couponCatID=array("others"=>"");
 $couponMerchant=array();
 $merchantID=array();
         while(($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                if($hasNext) {
$couponCategory[$KEY]=strtolower(trim($data[4]));
$merchantFetch=explode(".",strtolower($data[5]));
$couponMerchant[$KEY]=strtolower(trim($merchantFetch[0]));
$KEY++;
                    }
              $hasNext++;
         }
 $couponCategory=array_merge(array_unique($couponCategory));
 $couponMerchant=array_merge(array_unique($couponMerchant));
 if(!$couponCategory || !$couponMerchant) die("Required data not found");
 
 // check coupon category present in database
 for($i=0;$i<count($couponCategory);$i++) {
  if($couponCategory[$i]!=NULL) {
$check="select id from coupons_category where name='$couponCategory[$i]'";
list($CID)=mysql_fetch_row(mysql_query($check));
if($CID) $couponCatID[$CID]=$couponCategory[$i];
else {
$err="Category : ".ucwords($couponCategory[$i])." not found, please add category first";
break;
}
}
 }
 
 // check merchant present in database
 for($j=0;$j<count($couponMerchant);$j++) {
   $check1="select merchant_id from merchant where merchant_name='$couponMerchant[$j]'";
list($MID)=mysql_fetch_row(mysql_query($check1));
  if($MID) $merchantID[$MID]=$couponMerchant[$j];
else {
$err="Merchant : ".ucwords($couponMerchant[$j])." not found, please add merchant first";
break;
}
 }
 
 if(!@$err) $proceedMe="ok";  
}
if(@$proceedMe) {
$handle = fopen($_FILES['filename']['tmp_name'], "r");
$hasNext=0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if($hasNext) {
    $time=time();
$merchant=explode(".",strtolower($data[5]));
$merchant_name=strtolower(trim($merchant[0]));
$cat_name=strtolower(trim($data[4]));
$mer_id=array_search($merchant_name,$merchantID);
$cat_id=array_search($cat_name,$couponCatID);
$tags=strtolower($data[4]." ".$$data[1]." ".$data[0]." ".$data[3]." ".$data[5]." ".$merchantWebsite);
$exp= explode(" ",$data[2]);
$e_array=explode("-",$exp[0]);
$day=$e_array[0];
$month=$e_array[1];
$year=$e_array[2];
   $e_time = mktime(23, 59, 59, $month, $day, $year);
   //echo "Merchant ".$merchant_name." has id : ".$mer_id;
//echo "<br />Category ".$cat_name." has id : ".$cat_id."<hr />";
$import="INSERT into coupons(merchant_id,code,coupon_url,description,expiry,category,tags,time) values('$mer_id','$data[0]','$data[3]','$data[1]','$e_time','$cat_id','$tags','$time')";
mysql_query($import);
}
$hasNext++;
}
$err="Import Done";
}
}
?>