Git Product home page Git Product logo

csv2service's Introduction

csvtoservice

Is a PHP script to pull data from a CSV file on the web and turn it into a search and filter interface.

The parameters and options

All you need to provide is a URL that points to a CSV file and the script does the rest. You assign a variable to the main function that will get the HTML as properties.

 #PHP
 $myservice = csvtoservice('http://winterolympicsmedals.com/medals.csv');

The returned properties will be:

  • $myservice['form'] the HTML form with all possible fields contained in the dataset.
  • $myservice['table'] the data table of the information returned by the form submission.
  • $myservice['query'] the data in raw JSON (for debugging).
  • $myservice['json'] the YQL statement (for debugging).

If you want to tweak the outcome of the form and the table and you want to change the data names or remove parts of it you can set and options array:

 #PHP
 include('csvtoservice.php');
 $content = csvtoservice('http://winterolympicsmedals.com/medals.csv',
      array(
         'filter' => array(fieldnames),
         'rename' => array('field' => 'new field'),
         'preset' => array('field' => preset value),
         'prefill' => array('field1' => 'value1',
                            'field2' => 'value 2'),
         'uppercase' => Boolean            
      )  
 ); 
  • filter contains an array of fields to not show in the form or the table. This allows you to get rid of some of the data.
  • rename allows you to rename fields.
  • preset is an array of fields to preset with a hard value. This fields will be part of the query of the data, but will not be added to the form or displayed. This allows you to pre-filter the data.
  • prefill is an array of fields to pre-fill the form in case you want to give the end user a hint what they can search for.
  • uppercase - is a boolean value if the script should uppercase the first letter of the field name or not ex:('Country' instead of 'country').

Sample

#PHP
include('csvtoservice.php');
$content = csvtoservice('http://winterolympicsmedals.com/medals.csv',
   array(
       'filter' => array('eventgender', 'city'),
       'rename' => array('noc' => 'country'),
       'preset' => array('year' => 2002),
       'prefill' => array('sport' => 'skiing',
                          'medal' => 'gold'),
       'uppercase' => true  
      )  
   ); 
if($content) {
   if($content['form']) {
      echo$content['form']; 
   }
   if($content['table']) {
      echo$content['table']; 
   } 
} 

You can view in action:

csv2service's People

Contributors

thinkphp avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.