每天进步一点点 2016-10-28

51 阅读1分钟

1、

有2张表 father 表 和 son 表   id都是他们的主键\

         father中的字段为   id   fathername          son中的字段为   id  fathername  sonname \

                                       1         bob                                              1         1               jack    \

                                       2         nike                                              2         3               tom

                                       3         anda    \

然后要把son那里的fathername显示为英文名字     \

假设father表的信息我们存入到了redis中,son表的信息从数据库中取出来

$father = getConfig('id','name');

$orm = new Orm('son');\

$son = $orm->field('fathername,sonname');

//开始替换

           foreach ( $son as $key => &$value ) {
$fatherUid = $value ['fathername'];
$value ['fathername'] = $father [$fatherUid];
} \

$this->response=['list'=>$son];

最后是以json的风格显示在页面上的\

好吧,这是一个接口里面的一部分代码,返回数组list。 \

       \

2、负号与数字之间不要有空格    如 - 200  去掉中间的空格 ;\

     等于号两边要加一个空格 $x=9;     写为  $x = 9;

     括号内要各空一个空格   $orm = new Orm( 'haha' );

     日期是date类型,显示的格式是 xxxx-xx-xx;

     \

3、在function文件里面的一个方法getConfig(),蛮有意思,括号里面的参数默认是id name 这2个属性就是你要从这张表中查询的字段 例如getConfig('id','language');就是要从缓存到redis的原表中获取id language这2个字段。

\

4、还有一个error()方法

if(empty($id) || ! is_numeric($id)){ $this->error(-100,"您输入的id不能为空且必须是整数",200);}         \

 \

5、mysql比较全的一句查询语句

select选项  */字段列表 as 字段别名  from 表名 where 子句 group by子句  having 子句 order by子句 limit 子句;

\

\

                                                                                                                   -----------及时当勉励,岁月不饶人

                                                                                                                                                   2016-10-28\