HTML part
<div class="googlemap">
<?php
$this->load->library('session');
$bounds = $this->session->userdata('googlemap_bounds');
$bound_lat = 49.463251;
$bound_lng = 105.964504;
$gmap_zoom = 15;
if (isset($bounds) && !empty($bounds)) {
$bound_array = explode(',', $bounds);
if (!empty($bound_array)) {
$bound_lat = ($bound_array[0] + $bound_array[2]) / 2;
$bound_lng = ($bound_array[1] + $bound_array[3]) / 2;
$gmap_zoom = $bound_array[4];
}
}
if (isset($zar['googlemap']) && !empty($zar['googlemap'])):
?>
<div class="title">
Газрын байршил
</div>
<div class="embed-responsive embed-responsive-16by9">
<?php
echo $zar['googlemap'];
?>
</div>
<?php endif; ?>
<div class="title">
Газрын байршил
</div>
<div id="map_canvas" class="embed-responsive embed-responsive-16by9"></div>
</div>
JS code
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var initialBounds = null;
var mapCanvas = document.getElementById('map_canvas');
var mapOptions = {
center: new google.maps.LatLng(<?php echo $bound_lat; ?>,
<?php echo $bound_lng; ?>),
zoom: <?php echo $gmap_zoom; ?>,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(mapCanvas, mapOptions);
var styles = [
{
featureType: "all",
elementType: "labels",
stylers: [
{visibility: "on"}
]
}
];
map.setOptions({styles: styles});
google.maps.event.addListener(map, 'bounds_changed', function () {
try {
var zoom = map.getZoom();
var bounds = map.getBounds();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
var msg = 'gmb=' + ne.lat() + ',' + ne.lng() + ',' + sw.lat() + ',' +
sw.lng() + ',' + zoom;
if (initialBounds === null) {
initialBounds = bounds;
} else {
var link = '<?php echo site_url('zarwrite/gmap?'); ?>' + msg;
h2o.action(link, function (result) {
if (result.success) {
$('.googlemap .title').html(result.data);
}
});
}
} catch (err) {
alert(err);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
Thursday, October 23, 2014
article full select query using mysql concat, group_concat as json field
article full select with foreign table by one query
SELECT a.*, mediatype.code as mediatypecode, (SELECT CONCAT('[', GROUP_CONCAT(DISTINCT(CONCAT(CONCAT( CONCAT('{"id":"', attribute.id, '"'), CONCAT(', "filterable":"', attribute.filterable, '"') ), CONCAT(', "title":"', REPLACE(attribute.title, '"', '"'), '"'), CONCAT(', "value":"', REPLACE(article_attribute.value, '"', '"'), '"}'))) ORDER BY attribute.ordering ASC SEPARATOR ', ' ), ']') as attributes FROM (article) INNER JOIN article_attribute ON article.id = article_attribute.article_id INNER JOIN attribute ON article_attribute.attribute_id = attribute.id INNER JOIN attribute_item ON attribute.id = attribute_item.attribute_id WHERE article.id = a.id) as attributes, CONCAT('[', GROUP_CONCAT(DISTINCT(CONCAT(CONCAT( CONCAT('{"id":"', media.id, '"'), CONCAT(', "typecode":"', media.typecode, '"'), CONCAT(', "extension":"', media.extension, '"') ), CONCAT(', "path":"', REPLACE(media.path, '"', '"'), '"'), CONCAT(', "filename":"', REPLACE(media.filename, '"', '"'), '"}'))) ORDER BY media.typecode, article_media.ordering ASC SEPARATOR ', ' ), ']') as medias, seourl.url FROM (`article` as a) LEFT JOIN `seourl` ON `a`.`seourl_id` = `seourl`.`id` LEFT JOIN `mediatype` ON `a`.`mediatype_id` = `mediatype`.`id` LEFT JOIN `article_attribute` ON `a`.`id` = `article_attribute`.`article_id` LEFT JOIN `attribute` ON `article_attribute`.`attribute_id` = `attribute`.`id` LEFT JOIN `article_media` ON `a`.`id` = `article_media`.`article_id` LEFT JOIN `media` ON `article_media`.`media_id` = `media`.`id` WHERE `a`.`id` = '1' AND `mediatype`.`code` = 'zar' AND (a.approved = 1) GROUP BY `a`.`id` ORDER BY `a`.`createddate` desc
SELECT a.*, mediatype.code as mediatypecode, (SELECT CONCAT('[', GROUP_CONCAT(DISTINCT(CONCAT(CONCAT( CONCAT('{"id":"', attribute.id, '"'), CONCAT(', "filterable":"', attribute.filterable, '"') ), CONCAT(', "title":"', REPLACE(attribute.title, '"', '"'), '"'), CONCAT(', "value":"', REPLACE(article_attribute.value, '"', '"'), '"}'))) ORDER BY attribute.ordering ASC SEPARATOR ', ' ), ']') as attributes FROM (article) INNER JOIN article_attribute ON article.id = article_attribute.article_id INNER JOIN attribute ON article_attribute.attribute_id = attribute.id INNER JOIN attribute_item ON attribute.id = attribute_item.attribute_id WHERE article.id = a.id) as attributes, CONCAT('[', GROUP_CONCAT(DISTINCT(CONCAT(CONCAT( CONCAT('{"id":"', media.id, '"'), CONCAT(', "typecode":"', media.typecode, '"'), CONCAT(', "extension":"', media.extension, '"') ), CONCAT(', "path":"', REPLACE(media.path, '"', '"'), '"'), CONCAT(', "filename":"', REPLACE(media.filename, '"', '"'), '"}'))) ORDER BY media.typecode, article_media.ordering ASC SEPARATOR ', ' ), ']') as medias, seourl.url FROM (`article` as a) LEFT JOIN `seourl` ON `a`.`seourl_id` = `seourl`.`id` LEFT JOIN `mediatype` ON `a`.`mediatype_id` = `mediatype`.`id` LEFT JOIN `article_attribute` ON `a`.`id` = `article_attribute`.`article_id` LEFT JOIN `attribute` ON `article_attribute`.`attribute_id` = `attribute`.`id` LEFT JOIN `article_media` ON `a`.`id` = `article_media`.`article_id` LEFT JOIN `media` ON `article_media`.`media_id` = `media`.`id` WHERE `a`.`id` = '1' AND `mediatype`.`code` = 'zar' AND (a.approved = 1) GROUP BY `a`.`id` ORDER BY `a`.`createddate` desc
article hit count with session using article_model based codeigniter
private function _get_article_data($article) {
$category = $this->category_model->get($article['category_id']);
$this->support->set_working_category($category);
$data = array();
$data['category'] = $category;
//extend and traffic
$e_article_key = $this->support->get_article_session_name() . $article['id'];
$article_extend = $this->session->userdata($e_article_key);
$db_article_extend = $this->article_extend_model->get(array('article_id' => $article['id']));
if (isset($db_article_extend['hitcount']) &&
isset($article_extend['hitcount']) &&
$db_article_extend['hitcount'] != $article_extend['hitcount']) {
//if another process view this article
$article_extend = $db_article_extend;
}
if (!isset($article_extend['hitcount'])) {
//session not exists
if (isset($db_article_extend['hitcount'])) {
//db not set
$article_extend = $db_article_extend;
}
if (empty($article_extend)) {
//create hitcount in db
$article_extend = array();
$article_extend['article_id'] = $article['id'];
$article_extend['hitcount'] = 0;
}
$article_extend['hitcount'] = $article_extend['hitcount'] + 1;
$this->article_extend_model->save($article_extend);
$this->session->set_userdata($e_article_key, $article_extend);
}
$data['article_extend'] = $article_extend;
return $data;
}
$category = $this->category_model->get($article['category_id']);
$this->support->set_working_category($category);
$data = array();
$data['category'] = $category;
//extend and traffic
$e_article_key = $this->support->get_article_session_name() . $article['id'];
$article_extend = $this->session->userdata($e_article_key);
$db_article_extend = $this->article_extend_model->get(array('article_id' => $article['id']));
if (isset($db_article_extend['hitcount']) &&
isset($article_extend['hitcount']) &&
$db_article_extend['hitcount'] != $article_extend['hitcount']) {
//if another process view this article
$article_extend = $db_article_extend;
}
if (!isset($article_extend['hitcount'])) {
//session not exists
if (isset($db_article_extend['hitcount'])) {
//db not set
$article_extend = $db_article_extend;
}
if (empty($article_extend)) {
//create hitcount in db
$article_extend = array();
$article_extend['article_id'] = $article['id'];
$article_extend['hitcount'] = 0;
}
$article_extend['hitcount'] = $article_extend['hitcount'] + 1;
$this->article_extend_model->save($article_extend);
$this->session->set_userdata($e_article_key, $article_extend);
}
$data['article_extend'] = $article_extend;
return $data;
}
Wednesday, October 22, 2014
php дээр том жижиг үсэг ялгалгүй текст солих арга
$text = "while Машин. Wear socks машин их МАШ NOW";
$context = preg_replace_callback("/(маш)+/iu", function($a) {
return '<b>' . $a[1] . '</b>';
}, $text);
echo $context;
$context = preg_replace_callback("/(маш)+/iu", function($a) {
return '<b>' . $a[1] . '</b>';
}, $text);
echo $context;
Friday, October 17, 2014
mysql data to json object select using concat , group_concat
MySQL to JSON
Januari 23, 2007
I confess - I used to loop through my MySQL queries, in my server side
language of choice, to build JSON. But there is a far better way that
will save you some coding, add to simplicity and might even save some
valuable server time.
If you're running MySQL 4.1 or later you can use the nifty function
GROUP_CONCAT() together with the normal CONCAT() function to build all
your JSON straight from your SQL query.
Our SQL table.
A MySQL-query that returns JSON.
The returned JSON structure.
username | |
mike | mike@mikesplace.com |
jane | jane@bigcompany.com |
stan | stan@stanford.com |
SELECT
CONCAT("[",
GROUP_CONCAT(
CONCAT("{username:'",username,"'"),
CONCAT(",email:'",email),"'}")
)
,"]")
AS json FROM users;
[
{username:'mike',email:'mike@mikesplace.com'},
{username:'jane',email:'jane@bigcompany.com'},
{username:'stan',email:'stan@stanford.com'}
]
Combine multiple rows into one MySQL field using GROUP_CONCAT
SELECT GROUP_CONCAT(DISTINCT category.id) as ids FROM (`category`) LEFT JOIN `seourl` ON `category`.`seourl_id` = `seourl`.`id` WHERE (category.langcode IS NULL OR length(category.langcode) = 0 OR category.langcode='mn') AND `parent_id` IN ('10', '19', '20', '21', '22') AND (parent_id != 0) AND (deleted = 0)
result
array ( 'ids' => 35, 31);
same syntaxs
result
array ( 'ids' => 35, 31);
same syntaxs
GROUP_CONCAT(cast(concat(c.id,\': \',c.name) AS char)SEPARATOR \', \') AS categorie_names
Tuesday, October 14, 2014
how to make gradient color for IE8 using sass mixin
@mixin gradient($from-color, $to-color) {
background-color: mix($from-color, $to-color); /* Fallback */
background-image: -webkit-gradient
(linear, 0% 0%, 0% 100%, from($from-color), to($to-color));
background-image: -webkit-linear-gradient
(top, $from-color, $to-color);
background-image: -moz-linear-gradient
(top, $from-color, $to-color);
background-image: -ms-linear-gradient
(top, $from-color, $to-color);
background-image: -o-linear-gradient
(top, $from-color, $to-color);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient
(startColorStr='#{$from-color}', EndColorStr='#{$to-color}')";
}
don't forget # of
startColorStr='#{$from-color}'
Wednesday, October 8, 2014
init javascript with require.js after page loaded
<script type="text/javascript"> if(window.applicationCache){ window.applicationCache.addEventListener("error", function(e) { document.body.innerHTML = "Error fetching manifest: a good chance we are offline"; }); } function init() { var rjs = document.createElement("script"); rjs.src = "/assets/lib/require.js"; document.body.appendChild(rjs); var timer = setInterval(function(){ if(window.require) { require(["/init.js"]); clearInterval(timer); } }, 1); } if (window.addEventListener) window.addEventListener("load", init, false); else if (window.attachEvent) window.attachEvent("onload", init); else window.onload = init; </script>
Saturday, October 4, 2014
cpp oop example in gnu gcc
2d.h
namespace bor
{
const int LENGTH = 10;
const int TOP = 1;
const int RIGHT = 2;
const int BOTTOM = 3;
const int LEFT = 4;
class cube
{
private:
int arr[LENGTH][LENGTH];
protected:
int sector;
public:
void fill();
void change();
void print();
};
}
2d.cpp
#include <iostream>
#include <cstdlib>
#include "2d.h"
using namespace std;
namespace bor
{
void cube::fill(){
sector = TOP;
for(int i = 0; i < LENGTH; i++) {
for(int j = 0; j < LENGTH; j++) {
arr[i][j] = 1;
}
}
change();
}
void cube::change(){
int i = 0, j = 0;
do {
if(sector == TOP) {
if(j < LENGTH && arr[i][j] != 2)
{ arr[i][j] = 2; j++; }
else
{ j--; i++; sector = RIGHT; }
print();
}
if(sector == RIGHT) {
if(i < LENGTH && arr[i][j] != 2)
{ arr[i][j] = 2; i++; }
else
{ i--; j--; sector = BOTTOM; }
print();
}
if(sector == BOTTOM) {
if(j > -1 && arr[i][j] != 2)
{ arr[i][j] = 2; j--;
if(j < 0) { j++; i--; sector = LEFT; }
}
else
{ j++; i--; sector = LEFT; }
print();
}
if(sector == LEFT) {
if(i > -1 && arr[i][j] != 2)
{ arr[i][j] = 2; i--;
if(i < 0) { i++; j++; sector = TOP; }
}
else
{ i++; j++; sector = TOP; }
print();
}
if(i == 5 && j == 5) break;
} while (i == -1 || j == -1 || (i > -1 || j > -1 && arr[i][j] != 2) );
print();
}
void cube::print(){
cout<<endl<<endl;
for(int i = 0; i < LENGTH; i++) {
for(int j = 0; j < LENGTH; j++) {
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
system("pause");
}
}
main.cpp
#include <cstdlib>
#include <iostream>
#include "2d.h"
using namespace std;
using namespace bor;
int main(int argc, char* argv[])
{
cube *c = new cube();
c->fill();
return 0;
}
namespace bor
{
const int LENGTH = 10;
const int TOP = 1;
const int RIGHT = 2;
const int BOTTOM = 3;
const int LEFT = 4;
class cube
{
private:
int arr[LENGTH][LENGTH];
protected:
int sector;
public:
void fill();
void change();
void print();
};
}
2d.cpp
#include <iostream>
#include <cstdlib>
#include "2d.h"
using namespace std;
namespace bor
{
void cube::fill(){
sector = TOP;
for(int i = 0; i < LENGTH; i++) {
for(int j = 0; j < LENGTH; j++) {
arr[i][j] = 1;
}
}
change();
}
void cube::change(){
int i = 0, j = 0;
do {
if(sector == TOP) {
if(j < LENGTH && arr[i][j] != 2)
{ arr[i][j] = 2; j++; }
else
{ j--; i++; sector = RIGHT; }
print();
}
if(sector == RIGHT) {
if(i < LENGTH && arr[i][j] != 2)
{ arr[i][j] = 2; i++; }
else
{ i--; j--; sector = BOTTOM; }
print();
}
if(sector == BOTTOM) {
if(j > -1 && arr[i][j] != 2)
{ arr[i][j] = 2; j--;
if(j < 0) { j++; i--; sector = LEFT; }
}
else
{ j++; i--; sector = LEFT; }
print();
}
if(sector == LEFT) {
if(i > -1 && arr[i][j] != 2)
{ arr[i][j] = 2; i--;
if(i < 0) { i++; j++; sector = TOP; }
}
else
{ i++; j++; sector = TOP; }
print();
}
if(i == 5 && j == 5) break;
} while (i == -1 || j == -1 || (i > -1 || j > -1 && arr[i][j] != 2) );
print();
}
void cube::print(){
cout<<endl<<endl;
for(int i = 0; i < LENGTH; i++) {
for(int j = 0; j < LENGTH; j++) {
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
system("pause");
}
}
main.cpp
#include <cstdlib>
#include <iostream>
#include "2d.h"
using namespace std;
using namespace bor;
int main(int argc, char* argv[])
{
cube *c = new cube();
c->fill();
return 0;
}
Subscribe to:
Posts (Atom)