PhpToExcel EXPORT CODING EXAMPLE

PhpToExcel EXPORT CODING EXAMPLE - Hallo sahabat Tutorials, Pada Artikel yang anda baca kali ini dengan judul PhpToExcel EXPORT CODING EXAMPLE, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : PhpToExcel EXPORT CODING EXAMPLE
link : PhpToExcel EXPORT CODING EXAMPLE

Baca juga


PhpToExcel EXPORT CODING EXAMPLE

(1)write code for connection.php   file:

<?php

                $hostname = "localhost";
                $username = "root";
                $password = "";
                $database = "test";


                 $conn = mysql_connect("$hostname","$username","$password") or die(mysql_error());
                mysql_select_db("$database", $conn) or die(mysql_error());

?>
(2)write code for ExportToExcel.php file:

<?php
function ExportExcel($table)
{

$filename = "uploads/".strtotime("now").'.csv';

$sql = mysql_query("SELECT * FROM $table") or die(mysql_error());

$num_rows = mysql_num_rows($sql);
if($num_rows >= 1)
{
$row = mysql_fetch_assoc($sql);
$fp = fopen($filename, "w");
$seperator = "";
$comma = "";

foreach ($row as $name => $value)
{
$seperator .= $comma . '' .str_replace('', '""', $name);
$comma = ",";
}

$seperator .= "\n";
fputs($fp, $seperator);

mysql_data_seek($sql, 0);
while($row = mysql_fetch_assoc($sql))
{
$seperator = "";
$comma = "";

foreach ($row as $name => $value)
{
$seperator .= $comma . '' .str_replace('', '""', $value);
$comma = ",";
}

$seperator .= "\n";
fputs($fp, $seperator);
}

fclose($fp);
echo "Your file is ready. You can download it from <a href='$filename'>here!</a>";
}
else
{
echo "There is no record in your Database";
}


}
?>

(3)write  code for index.php   file:

<?php

include ("connection.php");
include ("ExportToExcel.php");

if(isset($_POST["submit"]))
{
ExportExcel("myrecord");
  }

?>

<html>
<head>
<style type="text/css">
body
{
margin: 0;
padding: 0;
background-color:#D6F5F5;
text-align:center;
}
.top-bar
{
width: 100%;
height: auto;
text-align: center;
background-color:#FFF;
border-bottom: 1px solid #000;
margin-bottom: 20px;
}
.inside-top-bar
{
margin-top: 5px;
margin-bottom: 5px;
}
.link
{
font-size: 18px;
text-decoration: none;
background-color: #000;
color: #FFF;
padding: 5px;
}
.link:hover
{
background-color: #9688B2;
}
</style>

</head>

<body>

<form name="export" method="post">
    <input type="submit" value="Click Me!" name="submit">
    </form>
   
<hr style="margin-top:300px;" />
   
    <div align="center" style="font-size:18px;"><a href="http://www.phpdevelopmenttricks.blogspot.com">&copy;om sir</a></div>

</body>
</html>






Demikianlah Artikel PhpToExcel EXPORT CODING EXAMPLE

Sekianlah artikel PhpToExcel EXPORT CODING EXAMPLE kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel PhpToExcel EXPORT CODING EXAMPLE dengan alamat link https://othereffect.blogspot.com/2016/08/phptoexcel-export-coding-example.html

0 Response to "PhpToExcel EXPORT CODING EXAMPLE"

Post a Comment