PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of David Doran   xDIF   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Examples of use.
Class: xDIF
Convert data to DIF spreadsheet file format
Author: By
Last change:
Date: 18 years ago
Size: 1,691 bytes
 

Contents

Class file image Download
<?php

/*******************************************************
 * EXAMPLE NUMBER #1
 * Here's an example of how to create a spreadsheet from
 * an array and a list of headers.
 */
 
require_once('xDif.class.php');
 
//The two arrays and string below are input data
 
$headers = array('Title','Genre','Author');
 
$data = array(
                  array(
'AdventureGuy','Adventure','John')
                  ,array(
'ActionMan','Action','Mike')
                  );
 
$title = "My First Spreadsheet";
 
//Create object and get converted data into string
 
$xDif = new xDif;
 
$difContent = $xDif->arrayToDif($headers,$data,$title);
 
//You can then save it to a file to open up
 
$xDif->toFile('Spreadsheet.dif',$difContent);
/*******************************************************/

/*******************************************************
 * EXAMPLE NUMBER #2
 * Here's an example of how to create a spreadsheet from
 * a MySQL database request
 * Instead of xDif->mysqlToDif you can use the following
 * xDif->mssqlToDif for MsSQL
 * xDif->pgToDif for PostgreSQL
 * xDif->ibaseToDif for Ibase/Firebird
 */
 
require_once('xDif.class.php');
 
//Connect to database and do query
 
$connection = mysql_connect('localhost','root','');
 
mysql_select_db('exampledb');
 
$queryResult = mysql_query("SELECT * FROM exampletable");
 
$title = "My First Spreadsheet";
 
//Create object and get converted data into string
 
$xDif = new xDif;
 echo
$difContent = $xDif->mysqlToDif($connection,$queryResult,$title);
 
//You can then save it to a file to open up
 
$xDif->toFile('MYSQLSpreadsheet.dif',$difContent);
/*******************************************************/