Tuesday, September 12, 2017

How to export data from database as an Excel Sheet

 <?php
ob_start();

include '../connection.php';
$branch22 = $_POST['item83'];
$course22 = $_POST['item88'];

 $output = '';

//get student list via button click values as 'export_studentinfo'
if(isset($_POST["export_studentinfo"]))  
{
                   
             
                    echo "<p > STUDENT LIST</p>";
                    echo "     <table id='studentdata' >";
                    echo "   <thead>";
                    echo "   <tr>";
                    echo "     <th>Student ID</th>";
                    echo "     <th>Student Name</th>";
                    echo "     <th>NIC</th>";
                    echo "    <th>Email</th>";
                    echo "    <th>Phone</th>";
                    echo "    <th>Address</th>";
                    echo "      <th>Date of Birth</th>";
                    echo " <th>Gender</th>";
                    echo "      <th>Occupation</th>";
                    echo "      <th>Registered Branch</th>";
                    echo " <th>Registration Date</th>";
                    echo "</tr>";
                    echo "</thead>";
                    echo "<tbody>";
       

       
$query = "SELECT * FROM student s, course c, student_course sc, student_branch sb, branch b where s.std_id = sb.std_id and sb.branch_id=b.branch_id and s.std_id=sc.std_id and sc.course_id=c.course_id and sc.course_id like '$course22' and sb.branch_id like '$branch22' order by b.name asc , c.course_id  ";

$result = $con->query( $query );

//get number of rows returned

$num_results = $result->num_rows;

if( $num_results > 0)
{
while( $row = $result->fetch_assoc() ){
//extract row
extract($row);
//creating new table row per record

echo "<tr>";

echo "<td>{$std_id}</td>";

echo "<td>{$fname}  {$lname}</td>";

echo "<td>{$nic}</td>";

echo "<td>{$email}</td>";

echo "<td>{$mobile}</td>";

echo "<td>{$address}</td>";

echo "<td>{$dob}</td>";

echo "<td>{$gender}</td>";

echo "<td>{$occupation}</td>";

echo "<td>{$name}</td>";

echo "<td>{$regDate}</td>";

}
echo "</tr>";

//end of while

       echo "</tbody>";
      $output .= '</table>';

           header("Content-Type: application/xls");  
           header("Content-Disposition: attachment; filename=student_details_excel.xls");   
           echo $output;
}

else
{
 echo "<script>alert('NO RECORDS FOUND'); window.location.href = '#'; </script>";
}

}

Creating a gif image using photoshop


1: Upload the images to Photoshop.

 To upload images into Photoshop, click File > Scripts > Load Files Into Stack.

Then, select Browse, and choose which files you'd like to use in your GIF. Then, click OK.


2: Open up the Timeline window.

To open Timeline, go to the top navigation, choose Window > Timeline. The Timeline will let you turn different layers on and off for different periods of time.

3: In the Timeline window, click 'Create Frame Animation.'

If it's not automatically selected, choose it from the drop-down menu.

4: Create a new layer for each new frame.

To do this, first select all your layers by going to the top navigation menu and choosing Select > All Layers. Then, click the menu icon on the right of the Timeline screen.
From the drop-down menu that appears, choose Create new layer for each new frame.


5: Open the same menu icon on the right, and choose 'Make Frames From Layers.'

This will make each layer a frame of your GIF.


6: Under each frame, select how long it should appear for before switching to the next frame.

To do this, click the time below each frame and choose how long you'd like it to appear.


7: At the bottom of the toolbar, select how many times you'd like it to loop.

The default will say Once, but you can loop it as many times as you want as needed.


8: Export created GIF

Save the GIF image by going to the top navigation bar and clicking File > Export > Save for Web (Legacy)...







 

Add a quicksearch feature in php

 Main HTML inside <head> 
(eg to check a student's nic from database and show complete nic and firstname if exist)

<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
    $("#search-box").keyup(function(){
        $.ajax({
        type: "POST",
        url: "quick_search.php",
        data:'keyword='+$(this).val(),
        beforeSend: function(){
            $("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
        },
        success: function(data){
            $("#suggesstion-box").show();
            $("#suggesstion-box").html(data);
            $("#search-box").css("background","#FFF");
        }
        });
    });
});

function selectCountry(val) {
$("#search-box").val(val);
$("#suggesstion-box").hide();
}
</script>

quick_search.php

<?php
require_once("../connection.php");

if(!empty($_POST["keyword"])) {
$query ="SELECT * FROM student WHERE nic like '" . $_POST["keyword"] . "%' ORDER BY nic LIMIT 0,6";

$result = mysqli_query($con, $query);
if(!empty($result)) {
?>
<ul id="country-list">

<?php
foreach($result as $country) {
?>
<li onClick="selectCountry('<?php echo $country["nic"]; ?>');"><?php echo $country["nic"]; ?>:<?php echo $country["fname"]; ?></li>
<?php } ?>
</ul>
<?php } } ?>

In the body
<input type="text" id="search-box" name="search-box" required placeholder="Enter NIC" size="60" name="nicpost" autocomplete="off" />
<div id="suggesstion-box" align="center"></div>

 

HTML Scripts to do some basic functions.

To Play a sound-file inside HTML
<script>
function playOkay(){
        $("body").append("<embed src='sliit_std_mng_sounds/all_okay.mp3' autostart='true' loop='false' width='2' height='0'></embed>");
}
</script>


Reload web-page after a certain time period
 <script>
 function autoRefresh1()
{
       window.location.reload();
}
 function timeRefresh()
 {
 setInterval('autoRefresh1()', 5000); // this will reload page after every 5 secounds
 }
    </script>

Redirect to another page after a certain time
<script type="text/JavaScript">
function timedRefresh(timeoutPeriod){
    setTimeout("window.location.href = '#';",timeoutPeriod);
}
</script>

A script to change another input box as per for the input 
(eg. when entered discount percentage, showing total fee)

        function getdiscount() {
            var txtFirstNumberValue = document.getElementById('txt1').value;
            var txtSecondNumberValue = document.getElementById('txt2').value;
            var result = parseFloat(txtFirstNumberValue) * parseFloat(txtSecondNumberValue/100);
           
            if (!isNaN(result))
            {
                document.getElementById('txt3').value = result;
                getfullc_fee();
              
            }
        }
</script>
<script>
function getfullc_fee()
{
    var txtFirstNumberValue = document.getElementById('txt1').value;
    var txtdis = document.getElementById('txt3').value;
    var fullfee = txtFirstNumberValue - txtdis;
                         

    //display the result
    document.getElementById('totalPrice').value = fullfee;

}
</script>




Implemting Google Drive File Uploader using OAuth

Implementing Google Drive Text File Uploader using OAuth 2.0 Creating Project and Registering your API with Google In this part we wil...