Ads were blocked - no problem. But keep in mind that developing HeidiSQL, user support and hosting takes time and money. You may want to send a donation instead.

export data page into excel

solikien's profile image solikien posted 4 years ago in General Permalink

I have some problem. I need to export data into excel but im stack in array

below is my coding and its actually successfully run.

$data = array(

'0' => array('name'=>'Ali' , 'word'=>'hai'),
         '1' => array('name'=>'John' , 'word'=>'hai'),
         '2' => array('name'=>'MArk' , 'word'=>'hai'),
         '3' => array('name'=>'Sofia' , 'word'=>'hai'),
         '4' => array('name'=>'Andy' , 'word'1=>'hai'),
         '5' => array('name'=>'Marry' , 'word' =>'hai')
        );

if(isset($_POST["ExportType"])) {

switch($_POST["ExportType"])
{
    case "export-to-excel" :
        // Submission from
        $filename = $_POST["ExportType"] . ".xls";       
        header("Content-Type: application/vnd.ms-excel");
        header("Content-Disposition: attachment; filename=\"$filename\"");
        ExportFile($limit); // call data di atas mengunakan function di bawah
        //$_POST["ExportType"] = '';
        exit();
   // default :
       // die("Unknown action : ".$_POST["action"]);
       // break;
}

} function ExportFile($records) { // function yag dgunakan apabila user enter export $heading = false; if(!empty($records)) foreach($records as $row) { if(!$heading) { // display field/column names as a first row echo implode("\t", array_keys($row)) . "\n"; $heading = true; } echo implode("\t", array_values($row)) . "\n"; } exit; } ?> <link rel="styles/bootstrap.min.css"> <link rel="styles/bootstrap-theme.min.css"> <script src="js/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script>

<div> <div id="container" > <div class="col-sm-6 pull-left"> <div class="btn-group pull-right"> <div id="export-menu"> <div id="export-to-excel"><a href="#">Export to excel</a></div> </div> </div> </div> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" id="export-form"> <input type="hidden" value='' id='hidden-type' name='ExportType'/> </form> </div></div>

</div> </body>
<script type="text/javascript"> $(document).ready(function() { jQuery('#export-menu div').bind("click", function() { var target = $(this).attr('id'); switch(target) { case 'export-to-excel' : $('#hidden-type').val(target); //alert($('#hidden-type').val()); $('#export-form').submit(); $('#hidden-type').val(''); break } }); }); </script>

But my problem is Iam using array inside array. means example one date have 24 hour have value of total attempt

$date = array() $hour=array(); for($i =0, $i<5; $i++){ $date[$i]="20150205"; // example of date $hour[$i] = array();

for($j=0; $j <24; $j ++){ $hour[$i][$j] = total_attempt; } }

question is how to put my data into $data ..Thank you

Please login to leave a reply, or register at first.