Skip to content

Instantly share code, notes, and snippets.

@gubi
Last active December 26, 2015 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gubi/7064678 to your computer and use it in GitHub Desktop.
Save gubi/7064678 to your computer and use it in GitHub Desktop.
PICOL icons categories
CREATE TABLE IF NOT EXISTS `icon_categories` (
`id` mediumint(9) NOT NULL AUTO_INCREMENT COMMENT 'Autoincrement ID',
`icon_name` varchar(100) NOT NULL COMMENT 'The name of icon',
`icon_src` varchar(255) NOT NULL COMMENT 'The path to icon file',
`category` enum('Technology','Finance','Culture','Education and Science','Nature','Live','Transportation, Construction & Living','Environment','Labor & Social Life','Nutrition','Health','Justice') NOT NULL COMMENT 'A category list',
`tags` varchar(100) NOT NULL COMMENT 'Comma separated tags',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
<?php
/**
* This function connect to the database
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @author Alessandro Gubitosi <gubi.ale@gotanotherway.com>
* @link
*
*/
function db_connect($config){
$dbname = "picol";
$pdo = new PDO("mysql:host=" . $config["database"]["host"] . ";dbname=" . $dbname, $config["database"]["username"], $config["database"]["password"], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
return $pdo;
}
?>
[database]
host = "MYSQL_SERVER_IP"
username = "DATABASE_USERNAME"
password = "DATABASE_PASSWORD"
[site]
url = "http://www.example.com" ;Remind to remove the slash at the end

Instructions

Execute database.sql as a SQL query in a MySQL database, then configure the file params.ini with database data.
Populate the database as you like and load the page table.php: you will see a simple table with all ordered... ;)

This is the list of all 10 categories of PICOL icons

  • Technology
  • Finance
  • Culture
  • Education and Science
  • Nature
  • Live
  • Transportation, Construction & Living Environment
  • Labor & Social Life
  • Nutrition
  • Health
  • Justice

Warning

These scripts are not tested!

<?php
/**
* Connect to database and take the ordered list of icons
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @author Alessandro Gubitosi <gubi.ale@iod.io>
* @link
*
**/
require_once("mysql_db_connect.inc.php");
$config = parse_ini_file("params.ini", 1);
$pdo = db_connect($config);
if (isset($_GET["tag"]) && trim($_GET["tag"]) !== "") {
$query = "select * from `icon_categories` where `tags` like '%" . addslashes($_GET["tag"]) . "%' order by `icon_name` asc"
} else {
$query = "select * from `icon_categories` order by `icon_name` asc";
}
$icon_categories = $pdo->query($query);
if($icon_categories->rowCount() > 0) {
$table = '<table cellpadding="5" cellspacing="5">';
while($categories_data = $icon_categories->fetch()) {
$tags = explode(",", $categories_data["tags"]);
$tag_link = "";
foreach($tags as $k => $tag){
$the_tag = ucfirst(trim($tag));
$tag_link .= '<a href="' . $config["site"]["url"] . '/table.php?tag=' . $the_tag . '" title="See all icons tagged &quot;' . $the_tag . '&quot;">' . $the_tag . '</a>';
if($k < count($tags)) {
$tag_link .= ", "
}
}
$table .= "<tr><th>" . $categories_data["category"] . "</th><td>" . $categories_data["icon_name"] . '<br /><img src="' . $categories_data["icon_src"] . '" /></td><td>' . $tag_link . '</td></tr>';
}
$table .= "</table>"
} else {
$table = "<h1>Oooops!</h1>I'm sorry but seems there's no icon in the table... I'm wrong?";
}
print $table;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment