限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >疑难片段

疑难片段

生成唯一订单号

//生成唯一订单id $order_id = date("Ymd").uniqid().mt_rand(0,100); date("Ymd") ;//年月日 uniqid();//随机数 mt_rand(0,100);//1-100的随机数

分享两个截取字符串已封装好的函数

函数1 // 截取字符串函数 function subtext($text, $length) { if(mb_strlen($text, 'utf8') > $length) return mb_substr($text, 0, $length, 'utf8').'...'; return $text; } 函数2 //函数解释: //msubstr($s

tp3.2数据更新(适用于记录登录次数)

$res1 = $user_coupon->where("user_id=$user_id")->setInc('num',$num); 相加相减使用 $User = M("User"); // 实例化User对象 $User->where('id=5')->setInc('score',3); // 用户的积分加3 $User->where('id=5'

时间与时间戳

时间转换为时间戳 strtotime(具体的时间) 即时时间戳 mktime()

tp3.2多表联查

table方法 $Model = new \Think\Model(); $list = $Model->table('shopping_coupon AS c,shopping_user_coupon AS uc')->where('c.id = uc.coupon_id')->select(); 更多方法参考:http://www.thinkphp.cn

tp3.2中使用fetchSql,不执行语句

tp3.2中使用fetchSql,不执行语句,只是做输出sql语句 $res_exi = $user_coupon->fetchSql()->where('user_id="'.$user_id.'" AND coupon_id="'.$id.'" ')->find(); if($res_exi){ echo "yes"; }else{ echo "no";