I'm twiting

访问统计

free counters

Saving a record along with its related records having hasMany association

For saving a record along with its related records having hasMany association, the data array should be like this:
Array
(
[Article] => Array
(
[title] => My first article
)
[Comment] => Array
(
[0] => Array
(
[comment] => Comment 1
[user_id] => 1
)
[1] => Array
(
[comment] => Comment 2
[user_id] => 2
)
)
)
The command for saving the above $data array would look like this:

PHP Interview questions from YAHOO

1. Which of the following will not add john to the users array? B
A. $users[] = ‘john’;
B. array_add($users,’john’);
C. array_push($users,‘john’);
D. $users ||= ‘john’;
2. What’s the difference between sort(), assort() and ksort? Under what circumstances would you use each of these?

sort()
asort()
ksort()

排序对象
元素的值
元素的值
元素键值

排序方式
字母顺序
字母顺序
字母顺序

重置索引
重置
不重置
不重置

3. What would the following code print to the browser? Why?
$num = 10;
function multiply(){
$num = $num * [...]

VirtualBox 不能上网问题。

virtualbox新版本老是连不上网络。网上的办法把问题高复杂了,其实刚装完的virtualbox需要简单配置下就可以了。
这里只讲虚拟机装xp的情况。
确认你的虚拟主机网络配置使用:NAT
ip:10.0.2.15
子网掩码:255.255.255.0
网关:10.0.2.2
DNS设成你自己的。
设完之后如果没起作用就重启你外面的系统。

MySQL 中逗号=Cross Join=Inner Join

转自:http://dev.mysql.com/doc/refman/5.0/en/join.html
The syntax of table_factor is extended in comparison with the SQL Standard. The latter accepts only table_reference, not a list of them inside a pair of parentheses.
This is a conservative extension if we consider each comma in a list of table_reference items as equivalent to an inner join. For example:
SELECT * FROM t1 LEFT JOIN [...]

Zabbix的一个bug

最近公司的项目要分解zabbix。分析它的代码的时候发现其数据库类有一个bug:使用mysql_pconnect建立一个数据库连接,却用mysql_close去关闭!这样做是关不掉的!因为mysql_pconnect建立的是一个持久化的连接,使用完毕会被放回连接池的,即使脚本执行完毕,这个连接也不会关闭。
一下是php.net对mysql_close的解释:
mysql_close() closes the non-persistent connection to the MySQL server that’s associated with the specified link identifier. If link_identifier isn’t specified, the last opened link is used.
一下是有问题的代码片段:
$mysql_server = $DB['SERVER'].( !empty($DB['PORT']) ? ‘:’.$DB['PORT'] : ”);
if (!$DB['DB']= mysql_pconnect($mysql_server,$DB['USER'],$DB['PASSWORD'])){
$error = ‘Error connecting to database ['.mysql_error().']‘;
$result = [...]

virtualbox极其慢的解决办法

最近virtualbox变得好慢。最后把audio改成oss就好了,原来用alsa的。不知道为什么。望高手指点。

使用jquery validation做表单异步验证

笔者在公司项目中需要对服务器的资产编号做惟一验证。也就是用户在提交表单的时候验证该服务器的资产编号是不是已经存在。如果不存在,则允许提交。如果已经存在,则还要判断该资产标号是不是属于本服务器,如果属于本服务器,则允许提交,否则拒绝提交。
一、准备
下载 jquery,和 jquery validation 插件。
下载后jquery改名为jquery.js。
然后解压jquery validation,得到jquery-validate目录,将目录下的jquery.validate.pack.js拷贝到和jquery.js同一目录下。笔者的这里假设目录为/var/www/test/webroot/js。
二、制作
把目录文件放到一起后我们可以开始制作了。
首先在需要作验证的页面加载这两个js文件。假设/var/www/test/webroot是网站根目录
<script src=”/js/jquery.js” type=”text/javascript”></script> <script src=”/js/jquery.validate.pack.js” type=”text/javascript”></script>
加载之后我们就可以调用它们的方法了。
三、总结
其实整个过程是很简单的。无非就是当用户输入的内容”change“的时候。我们就向服务器端请求一次,看看新的value是不是可用。然后再根据这一点我们再通过视图(这里就是页面)提示用户当前值是否可用。如果这个值是不合法的,那我们不允许表单提交。

做一个37℃的男人

做一个37℃的男人有种男人,他们知书达理,为人处事从不张扬,但也不消极。这种男人,一直在社会竞争中全力拼搏着,虽然至今没有登上“顶峰”,但他们不以物喜不以己悲,依然抱着一颗平常心。这种男人,心中有自己的人生目标,凡事力求完美——他们平凡而不平庸,低调而不颓废。他们体贴温柔,洁净温暖;他们不温不火,不左不右。因为这种类似体温的感觉,所以这样的男人就叫——37℃男人