Tech issues about computer, networks and programming and answers during or after my work. 工作及业余时间遇到的各种电脑,网络以及编程等相关的技术问题及解答
Oct 18, 2012
Do group by after order by in SQL
SELECT * FROM (
SELECT * FROM (
SELECT `m`.`id` AS `m__id`, `m`.`appliedat` AS `m__appliedat`, `m`.`idstudent` AS `m__idstudent`, `m`.`idclass` AS `m__idclass`, `m`.`comment` AS `m__comment`, `m`.`score` AS `m__score`, `m`.`created_by` AS `m__created_by`, `m`.`updated_by` AS `m__updated_by`, `m`.`deleted_at` AS `m__deleted_at`, `m`.`created_at` AS `m__created_at`, `m`.`updated_at` AS `m__updated_at`, `m`.`schoolcode` AS `m__schoolcode`, `c`.`id` AS `c__id`, `c`.`name` AS `c__name`, `c`.`code` AS `c__code`, `c`.`description` AS `c__description`, `c`.`idtype` AS `c__idtype`, `c`.`value` AS `c__value`, `c`.`idroot` AS `c__idroot`, `c`.`lft` AS `c__lft`, `c`.`rgt` AS `c__rgt`, `c`.`level` AS `c__level`, `c2`.`id` AS `c2__id`, `c2`.`name` AS `c2__name`, `c2`.`code` AS `c2__code`, `c2`.`description` AS `c2__description`, `c2`.`idtype` AS `c2__idtype`, `c2`.`value` AS `c2__value`, `c2`.`idroot` AS `c2__idroot`, `c2`.`lft` AS `c2__lft`, `c2`.`rgt` AS `c2__rgt`, `c2`.`level` AS `c2__level`, `c3`.`id` AS `c3__id`, `c3`.`name` AS `c3__name`, `c3`.`code` AS `c3__code`, `c3`.`idroot` AS `c3__idroot`, `c3`.`lft` AS `c3__lft`, `c3`.`rgt` AS `c3__rgt`, `c3`.`level` AS `c3__level`, `c4`.`id` AS `c4__id`, `c4`.`name` AS `c4__name`, `c4`.`code` AS `c4__code`, `c4`.`idroot` AS `c4__idroot`, `c4`.`lft` AS `c4__lft`, `c4`.`rgt` AS `c4__rgt`, `c4`.`level` AS `c4__level` FROM `mark` `m`
INNER JOIN `mark_criteria` `m2` ON (`m`.`id` = `m2`.`idmark`)
INNER JOIN `criteria` `c` ON `c`.`id` = `m2`.`idcriteria`
INNER JOIN `mark_criteria` `m3` ON (`m`.`id` = `m3`.`idmark`)
INNER JOIN `criteria` `c2` ON `c2`.`id` = `m3`.`idcriteria` AND (`c2`.`idtype` = 9)
LEFT JOIN `criteria_type` `c3` ON `c`.`idtype` = `c3`.`id`
LEFT JOIN `criteria_type` `c4` ON `c2`.`idtype` = `c4`.`id`
WHERE (`c`.`id` IN (46, 50) AND `m`.`idstudent` = 50 AND `m`.`idclass` = 12 AND (`m`.`deleted_at` IS NULL) AND ((`m`.`schoolcode` = 12345 OR `m`.`schoolcode` IS NULL)))
ORDER BY `m`.`appliedat` DESC, `m`.`created_at` DESC
) AS T
GROUP BY `c__id`
) AS T
ORDER BY `m__appliedat` DESC, `m__created_at` DESC
http://topic.csdn.net/u/20111024/18/4423fd26-60b5-4ed6-b541-16ba38d7356c.html
Sep 19, 2012
Transfer array from PHP to jQuery
I wanted to transfer an array from server side PHP to client side jQuery in metadata, as following:
...
$meta = metadata(array('invalid_chars' => $this->getUnwantedCharCodeArray()));
return sprintf('<div class="token %s">%s</div>', $meta, $output);
...
While in this way what I got at client side is an object, which could not be used in method like $.inArray():
$('.token').metadata().invalid_chars was an object like object { 0=35, 1=94....}, what I wanted was an array [35, 94...]
Tried .toArray() and $.makeArray(), wouldn't work....
Finally I found a solution: json_encode at the server side and parseJSON at the client side:
Server side:
...
$meta = metadata(array('invalid_chars' => json_encode($this->getUnwantedCharCodeArray())));
return sprintf('<div class="token %s">%s</div>', $meta, $output);
...
Client side:
if ($.inArray(charCode, $.parseJSON($('.token').metadata().invalid_chars)) > -1 ) { ...
...
$meta = metadata(array('invalid_chars' => $this->getUnwantedCharCodeArray()));
return sprintf('<div class="token %s">%s</div>', $meta, $output);
...
While in this way what I got at client side is an object, which could not be used in method like $.inArray():
$('.token').metadata().invalid_chars was an object like object { 0=35, 1=94....}, what I wanted was an array [35, 94...]
Tried .toArray() and $.makeArray(), wouldn't work....
Finally I found a solution: json_encode at the server side and parseJSON at the client side:
Server side:
...
$meta = metadata(array('invalid_chars' => json_encode($this->getUnwantedCharCodeArray())));
return sprintf('<div class="token %s">%s</div>', $meta, $output);
...
Client side:
if ($.inArray(charCode, $.parseJSON($('.token').metadata().invalid_chars)) > -1 ) { ...
Jul 4, 2012
Install skype 4.0 on ubuntu 12.04 64-bit
上周闲得蛋疼把ubuntu升级到12.04,还好没出啥问题。
今天又手欠,想把skype升级到4.0.
结果升级前需要卸载原先的skype2.2,没想到卸了之后不仅4.0没有安装成功,2.2也再装不上了,我哭。。。
谁教我够贱,只好股沟来股沟去,总算解决了,呼呼。
http://www.mindwerks.net/2012/06/skype-4-0-on-ubuntu-precise-12-04-64-bit-2/
今天又手欠,想把skype升级到4.0.
结果升级前需要卸载原先的skype2.2,没想到卸了之后不仅4.0没有安装成功,2.2也再装不上了,我哭。。。
谁教我够贱,只好股沟来股沟去,总算解决了,呼呼。
http://www.mindwerks.net/2012/06/skype-4-0-on-ubuntu-precise-12-04-64-bit-2/
- Remove old skype packages if they exist:
sudo apt-get purge skype skype-bin
- Download latest Skype (4.0) (fake) 64-bit package for Ubuntu 10.04+. It might say skype 2.2 beta on the screen, they have yet to update the page. The download link goes to the 4.0 version.
- Install the necessary support libraries:
sudo apt-get install ia32-libs lib32stdc++6 lib32asound2
- Install the skype binary package itself:
sudo dpkg -i skype-ubuntu_4.0.0.7-1_amd64.deb
Jun 28, 2012
Solution to ubuntu 12.04 sqlite missing
Yesterday I upgrade Ubuntu on my PC in office from 11.10 to 12.04, everything seemed ok.
However, unfortunately, this morning when I tried to clean cache of a symfony project, it reported a Fatal error:
PHP Fatal error: Class 'SQLiteDatabase' not found in /home/htsg/workspace/esr-momentum/lib/vendor/symfony/lib/cache/sfSQLiteCache.class.php on line 166
After searching online, I found that 12.04 uses sqlite3 as default, and doesn't install sqlite any more.
I tried a solution which install obsoleted lib via pecl, but failed when did make.
So I had to try another way:
1. downloaded a old version sqlite package from http://packages.ubuntu.com/natty-updates/php5-sqlite
2. extracted the deb file, found the sqlite.so file, copy it to /usr/lib/php5/20090626
3. change the file privilege to root:root
4. create a new configure file sqlite.ini in /etc/php5/conf.d, whose content is
extension=sqlite.so
5. sudo service apache2 restart
done.
However, unfortunately, this morning when I tried to clean cache of a symfony project, it reported a Fatal error:
PHP Fatal error: Class 'SQLiteDatabase' not found in /home/htsg/workspace/esr-momentum/lib/vendor/symfony/lib/cache/sfSQLiteCache.class.php on line 166
After searching online, I found that 12.04 uses sqlite3 as default, and doesn't install sqlite any more.
I tried a solution which install obsoleted lib via pecl, but failed when did make.
So I had to try another way:
1. downloaded a old version sqlite package from http://packages.ubuntu.com/natty-updates/php5-sqlite
2. extracted the deb file, found the sqlite.so file, copy it to /usr/lib/php5/20090626
3. change the file privilege to root:root
4. create a new configure file sqlite.ini in /etc/php5/conf.d, whose content is
extension=sqlite.so
5. sudo service apache2 restart
done.
Jun 14, 2012
解决Ajax调用前后页面提示在IE和Chrome中不显示的问题 (solution to indicator wont appear during Ajax call on IE and Chrome)
开发一个页面,页面中的部分内容采用Ajax更新,在Ajax调用前,向页面中添加信息载入提示信息(一个旋转的动画图标),在Ajax调用后,从页面中除去该提示信息。流程如下:
添加提示 >> Ajax调用 >> 除去提示
在开发过程中发现,如果Ajax调用采用异步方式,调用时FF浏览器中不会出现提示,因为添加和除去提示的动作都与Ajax调用异步执行了,也就是说,没等Ajax调用完成,除去提示的语句就被执行了。因此尝试将Ajax调用方式改为同步(其实这是不好的),结果在FF中达到了预期的效果。
然而换到IE和Chrome中,提示依然不出现。经过调研,发现这是因为:同步调用的Ajax,在IE和Chrome中都会阻塞调用前的DOM更新(http://bugs.jquery.com/ticket/7464,http://bugs.jquery.com/ticket/8819)。尝试用setTimeout函数调用Ajax,依然不能解决问题。
继续调研,最终找到了解决方案:
1. Ajax调用方式设置为异步
2. 把添加提示和除去提示从Ajax调用语句的前后,分别转移到Ajax调用内的beforeSend和complete属性的函数中去
流程如下:
$.ajax({
type : 'POST',
url : url,
async : true,
beforeSend : function() {
添加提示
},
complete : function() {
除去提示
},
success : function(data) {
....
}
});
这样一来,把提示信息的处理交给了jQuery的.ajax函数,问题得到解决。
参考链接:
http://stackoverflow.com/questions/2227397/jquery-ajax-beforesend-and-complete-working-properly-on-firefox-but-not-on-ie8
http://stackoverflow.com/questions/5182466/ajax-requests-on-chrome-using-jquery-freezes-page-untill-they-all-complete
添加提示 >> Ajax调用 >> 除去提示
在开发过程中发现,如果Ajax调用采用异步方式,调用时FF浏览器中不会出现提示,因为添加和除去提示的动作都与Ajax调用异步执行了,也就是说,没等Ajax调用完成,除去提示的语句就被执行了。因此尝试将Ajax调用方式改为同步(其实这是不好的),结果在FF中达到了预期的效果。
然而换到IE和Chrome中,提示依然不出现。经过调研,发现这是因为:同步调用的Ajax,在IE和Chrome中都会阻塞调用前的DOM更新(http://bugs.jquery.com/ticket/7464,http://bugs.jquery.com/ticket/8819)。尝试用setTimeout函数调用Ajax,依然不能解决问题。
继续调研,最终找到了解决方案:
1. Ajax调用方式设置为异步
2. 把添加提示和除去提示从Ajax调用语句的前后,分别转移到Ajax调用内的beforeSend和complete属性的函数中去
流程如下:
$.ajax({
type : 'POST',
url : url,
async : true,
beforeSend : function() {
添加提示
},
complete : function() {
除去提示
},
success : function(data) {
....
}
});
这样一来,把提示信息的处理交给了jQuery的.ajax函数,问题得到解决。
参考链接:
http://stackoverflow.com/questions/2227397/jquery-ajax-beforesend-and-complete-working-properly-on-firefox-but-not-on-ie8
http://stackoverflow.com/questions/5182466/ajax-requests-on-chrome-using-jquery-freezes-page-untill-they-all-complete
IE7中z-index相关问题解决办法 (z-index problem on IE7 solution)
开发一个页面,页面中有两个临近的元素,上边的是一个导航下拉菜单,下边的是一个jquery-ui的slider。在FF和Chrome中都可正常显示,但是在IE7中,本应被下拉菜单遮住的slider反而出现在菜单的前面。
这是由于一个IE7的bug:“In Internet Explorer positioned elements generate a new stacking context, starting with a z-index value of 0. Therefore z-index doesn’t work correctly”,所以IE7不能正确处理不同的设置了position属性的页面元素下的子元素的z-index顺序,常常导致z-index序号大的子元素反而被另一页面元素下z-index序号小的子元素所覆盖。
一种解决办法是:设置z-index序号大的子元素的父元素的z-index属性,赋一个更大的序号。这个办法解决了上面提到的导航下拉菜单和slider在IE7中的显示问题。至于为什么有效,不知其所以然。。。
参考于这篇博文:http://brenelz.com/blog/squish-the-internet-explorer-z-index-bug/
这是由于一个IE7的bug:“In Internet Explorer positioned elements generate a new stacking context, starting with a z-index value of 0. Therefore z-index doesn’t work correctly”,所以IE7不能正确处理不同的设置了position属性的页面元素下的子元素的z-index顺序,常常导致z-index序号大的子元素反而被另一页面元素下z-index序号小的子元素所覆盖。
一种解决办法是:设置z-index序号大的子元素的父元素的z-index属性,赋一个更大的序号。这个办法解决了上面提到的导航下拉菜单和slider在IE7中的显示问题。至于为什么有效,不知其所以然。。。
参考于这篇博文:http://brenelz.com/blog/squish-the-internet-explorer-z-index-bug/
Apr 5, 2012
mergePostValidator sfValidatorCallback throw error on widget
throw new sfValidatorErrorSchema($validator, array('roll_classes_list' => $error));
Mar 30, 2012
Ubuntu 11.10, remove annoying "restart to complete updates"
from http://ubuntuforums.org/showthread.php?t=1859432
sudo mv /var/run/* /run/ sudo mv /var/lock/* /run/lock/ sudo rm -r /var/run sudo rm -r /var/lock sudo ln -s /run /var/run sudo ln -s /run/lock /var/lock sudo rm /run/dbus/*
Mar 28, 2012
Ubuntu 11.10 desktop 3D Cube effects enable
http://www.noobslab.com/2011/10/enable-compiz-desktop-cube-in-ubuntu.html
按照这篇指南搞了之后,快捷工具栏不见了,幸好下面还有高人:
Heres How I got the cube to work in very few steps:
Get compiz app. run it.
UNCHECK UNITY plugin.
goto general options->desktop size, set horizontal to 4, vertical to 1, and # of desktops to 4.
check the cube, tell it to stop using wall or w/e.
check rotate cube.
recheck the unity plugin, and tell it to ignore the conflict.
Done.
Digest from http://www.noobslab.com/2011/10/enable-compiz-desktop-cube-in-ubuntu.html
按照这篇指南搞了之后,快捷工具栏不见了,幸好下面还有高人:
Heres How I got the cube to work in very few steps:
Get compiz app. run it.
UNCHECK UNITY plugin.
goto general options->desktop size, set horizontal to 4, vertical to 1, and # of desktops to 4.
check the cube, tell it to stop using wall or w/e.
check rotate cube.
recheck the unity plugin, and tell it to ignore the conflict.
Done.
Digest from http://www.noobslab.com/2011/10/enable-compiz-desktop-cube-in-ubuntu.html
Subscribe to:
Posts (Atom)