<?php //统计访问量 if (!@ $fp = fopen ( "num.txt" , "r" )){ echo "num.txt文件创建成功!<br>" ; } $num =@ fgets ( $fp ,12); if ( $num == "" ) $num =0; $num ++; @fclose( $fp ); $fp = fopen ( "num.txt" , "w" ); fwrite( $fp , $num ); echo "你是第 <font size='50' color='red'><b><i>" . $num . "</i></b></font> 个访问者" ; fclose( $fp ); ?> |
PHP全局变量
<?php $zy = "你好" ; $zyy = "PHP" ; function lxt(){ echo $zy . "<br/>" ; //没有输出 global $zyy ; //在函数内部定义全局变量 echo $zyy . "<br/>" ; //输出PHP } lxt(); ?> |
利用反射实现对象调用方法
<?php class Person{ function say(){ return "say" ; } function run( $speed , $addr ){ return "我是A,我在" . $addr . "跑步,速度是" . $speed ; } } //利用反射实现对象调用方法 $tom = new Person; $med = new ReflectionMethod( $tom , 'say' ); //反射方法对象 echo $med -> invoke( $tom ); //对象调用方法 //输出:say echo ( '<br/>' ); $john = new Person; $m = new ReflectionMethod( $john , 'run' ); //反射方法对象 echo $m -> invokeArgs( $john , array ( '20' , 'yichang' )); //输出:我是A,我在yichang跑步,速度是20 |
iwebshop常用记录
//进销存,查询库存信息 function inventory() { //搜索条件 //$search = IReq::get('search');//可由前端传过来 $page = IReq::get( 'page' ) ? IFilter::act(IReq::get( 'page' ), 'int' ) : 1; //页码 //条件筛选处理 list( $join , $where ) = goods_class::getSearchCondition( $search ); //拼接sql $goodsHandle = new IQuery( 'goods as go' ); $goodsHandle ->order = "go.id desc" ; $goodsHandle ->fields = "distinct go.id,go.goods_no,go.name,go.sell_price,go.market_price,go.store_nums,go.img,go.is_del,go.seller_id,go.is_share" ; $goodsHandle ->page = $page ; $goodsHandle ->where = $where ; $goodsHandle ->join = $join ; //$this->search = $search; $this ->goodsHandle = $goodsHandle ; $this ->redirect( "inventory" ); } |
//出库入库 public function importAndExportGoods() { $goodsId = IFilter::act(IReq::get( 'goods_id' ), 'post' ); //商品Id $goodsName = trim(IReq::get( 'goodsName' , 'post' )); //商品名称 $amount = trim(IReq::get( 'amount' , 'post' )); //数量 $customer = trim(IReq::get( 'customer' , 'post' )); //客户 $note = trim(IReq::get( 'note' , 'post' )); //备注 $adminName = trim(IReq::get( 'adminName' , 'post' )); //操作员姓名 $type = trim(IReq::get( 'type' , 'post' )); //类型:import export $goodsDB = new IModel( "goods" ); $where = "id = " . $goodsId ; $goodsRow = $goodsDB ->getObj( $where ); $store_nums = $goodsRow [ 'store_nums' ]; //库存 //修改商品的库存 if ( $type == "import" ){ //入库 $store_nums = $store_nums + $amount ; } else if ( $type == "export" ){ //出库 if ( $store_nums < $amount ){ //库存不够 die (JSON::encode( array ( 'code' => 5, 'info' => '库存不足,请重新输入出库数量!' ))); } $store_nums = $store_nums - $amount ; } $goodsRow [ 'store_nums' ] = $store_nums ; $where = "id = " . $goodsId ; $goodsDB ->setData( $goodsRow ); $goodsDB ->update( $where ); //更新库存 //将出入库记录添加到数据库 $recordDB = new IModel( "in_out_record" ); $record = array ( 'type' => $type , 'operator' => $adminName , 'create_time' => date ( 'y-m-d h:i:s' ,time()), 'goods_id' => $goodsId , 'goods_name' => $goodsName , 'amount' => $amount , 'customer' => $customer , ); $recordDB ->setData( $record ); $record_id = $recordDB ->add(); //添加 die (JSON::encode( array ( 'code' => 2, 'info' => '操作成功' , 'store_nums' => $store_nums ))); } |