From: Gabriel Dunne Date: Sun, 18 Dec 2011 17:17:05 +0000 (-0800) Subject: Update tag count on duplicate key X-Git-Tag: v0.1~57 X-Git-Url: https://git.quilime.com/?a=commitdiff_plain;h=14f44b5c179ae0b9dd7ae5fa07f3291b0cbea9ba;p=clmpr.git Update tag count on duplicate key --- diff --git a/clmpr.sql b/clmpr.sql index ac03432..6a9a88a 100644 --- a/clmpr.sql +++ b/clmpr.sql @@ -19,7 +19,7 @@ CREATE TABLE `tags` ( `count` int(9) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `tag` (`tag`) -) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; +) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; CREATE TABLE `users` ( `id` int(9) NOT NULL AUTO_INCREMENT, diff --git a/get.php b/get.php index 34679a9..b61ed16 100644 --- a/get.php +++ b/get.php @@ -94,6 +94,12 @@ case 'xml' : + + @@ -106,19 +112,11 @@ case 'xml' : ?>
-

- - -
diff --git a/put.php b/put.php index 7df006e..a78631b 100644 --- a/put.php +++ b/put.php @@ -17,22 +17,27 @@ try { $dbh = get_db_connection(); $dbh->beginTransaction(); - # insert clump - $sql = "INSERT INTO `clmpr`.`clumps` ( `user_id`, `title` , `url` , `tags`, `description`, `date` ) - VALUES ( ?, ?, ?, ?, ?, NOW() ) "; - $q = $dbh->prepare($sql); - $insert = $q->execute( array( $user['id'], $params['title'], $params['url'], $params['tags'], $params['description'] )); - # process tags $tags = explode(" ", $params['tags']); + $tags = array_unique($tags); if (count($tags) > 0) { - foreach($tags as $tag) { - $sql = "INSERT INTO `clmpr`.`tags` ( `tag` ) VALUES ( ? ) "; + foreach($tags as $key => $tag) { + $sql = "INSERT INTO `clmpr`.`tags` ( `tag`, `count` ) + VALUES ( ?, 1 ) + ON DUPLICATE KEY UPDATE + `count` = `count` + 1"; $q = $dbh->prepare($sql); $q->execute( array( $tag )); } } + # insert clump + $sql = "INSERT INTO `clmpr`.`clumps` ( `user_id`, `title` , `url` , `tags`, `description`, `date` ) + VALUES ( ?, ?, ?, ?, ?, NOW() ) "; + $q = $dbh->prepare($sql); + $insert = $q->execute( array( $user['id'], $params['title'], $params['url'], implode(" ", $tags), htmlentities($params['description']) )); + + $dbh = null; echo "clumped.

"; diff --git a/style.css b/style.css index 971a6c1..21f091d 100644 --- a/style.css +++ b/style.css @@ -105,11 +105,11 @@ ul.tags, ul.tags li { display:inline; } ul.tags li { - background:#eee; + background:#eef; padding:0 4px; margin:0 1px; } ul.tags li a { - color:#bbb; + color:#aaf; }