Tag Archives: json

MySQL vs/and/plus/more JSON

Here are a few things that we can use / read about MySQL and JSON.

Small benchmark tests of reading 20000

Krasimir Tsonev has made a small benchmark tests of reading 20000 from a MySQL db and from a JSON file.

I’m gonna just put the *end* results. You can read all the article on Krasimir’s blog about MySQL vs JSON file data storing benchmark results.

MySQL

ab -n 30 -c 30 http://localhost/mqsql.php
Concurrency Level:      30
Time taken for tests:   30.518 seconds

 

JSON

ab -n 30 -c 30 http://localhost/json.php
Concurrency Level:      30
Time taken for tests:   3.384 seconds
MySQL query to JSON
username email
mike [email protected]
jane [email protected]
stan [email protected]

The MySQL query

SELECT 
     CONCAT("[",
          GROUP_CONCAT(
               CONCAT("{username:'",username,"'"),
               CONCAT(",email:'",email),"'}")
          )
     ,"]") 
AS json FROM users;

The JSON result

[
     {username:'mike',email:'[email protected]'},
     {username:'jane',email:'[email protected]'},
     {username:'stan',email:'[email protected]'}
]

Got this from http://www.thomasfrank.se/mysql_to_json.html.

 

 

 

 

 

 

Parse JSON files with JQUERY – render, list, sort, search, paginate?

So,

I’m working on a project that needs to improve the user experience on a particular website. The website uses a particular CMS that uses php smarty template and caches some pages… even though the solution isn’t the best!

We pretend to hit the some 30.000 unique visitors/month just in the following 3 months and improve retention/sales.

For this, we will still use the current CMS but we will export all data to JSON files.
This JSON files will be stored on a CDN and will be used to render, on the client side, the content.

On the first approach we tried to use dynatable.com witch has/had some bugs… so I looked for another similar solution and found jPList – jQuery Data Grid Controls jPList – jQuery Data Grid Control.

Sorting

  • Ascending and descending sorting
  • Sort numbers, text, date and time
  • SELECT and UL/LI sort controls

Pagination

  • Auto pagination control
  • Google style pagination
  • Items per page control

Filter and Search

  • Any number of textbox filters
  • Any number of dropdown filters
  • Filter by jQuery path or by text content

Toggle Filters

  • Checkbox and radio button filters
  • Button filter controls
  • Range filter controls

Data sources

  • PHP + MySQL / SQLite
  • ASP.NET + Sql Server
  • XML + XSLT / JSON

HTML Layout

  • Works with DIVs, Tables, Lists, …
  • List, Grid and Thumbs view
  • Responsive controls and layout

JavaScript Templates

  • Handlebars
  • Mustache
  • Any other template engine

Storage

  • Supports local storage
  • Supports cookies
  • Has deep links support

CMS and Frameworks

  • WordPress Plugin
  • Groovy, Grails and MySQL
  • NodeJS, Express and MySQL

jQuery UI

  • jQuery UI range slider filter
  • jQuery UI date picker range filter

 

Browser Compatibility

  • Internet Explorer 8+
  • All modern browsers
  • Mobile Devices

Other Controls

  • Reset button Control
  • Back button Control
  • Counter Controls

php rss feed to json

This is a simple script that grabs a rss file and converts it to json.
It was copied from http://onwebdev.blogspot.com/2011/08/php-converting-rss-to-json.html but it has some little changes that will work 100%!

In fact the original code was putting every title, description, pubDate and guid in a new array entry.

$feed = new DOMDocument();
 $feed->load('file.rss');
 $json = array();
 $json['title'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
 $json['description'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
 $json['link'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('link')->item(0)->firstChild->nodeValue;
 $items = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('item');

 $json['item'] = array();
 $i = 0;

 foreach($items as $key => $item) {
 $title = $item->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
 $description = $item->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
 $pubDate = $item->getElementsByTagName('pubDate')->item(0)->firstChild->nodeValue;
 $guid = $item->getElementsByTagName('guid')->item(0)->firstChild->nodeValue;

 $json['item'][$key]['title'] = $title;
 $json['item'][$key]['description'] = $description;
 $json['item'][$key]['pubdate'] = $pubDate;
 $json['item'][$key]['guid'] = $guid; 
 }

echo json_encode($json);