首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

随机六位大写字母商品编号

2012-09-02 
随机6位大写字母商品编号function ondemo(){$i0$ttt$fffwhile ($i9999) {$i++$ttt$this-ran

随机6位大写字母商品编号
function ondemo(){

    $i=0;

    $ttt='';

    $fff='';

    while ($i<9999) {

    $i++;

    $ttt=$this->random(6);

    if($_ENV['pay']->check_rand($ttt)){

    $fff=$ttt;

    if($_ENV['pay']->insert_rand($fff)) echo $fff;

    break;

    }

    }

    if(empty($fff)) echo 'error';

    }

   

    function random($length, $string = 'ABCDEFGHJKLMNPQRSTUVWXYZ')  

{  

    $random = '';  

    $strlen = strlen($string);  

    for ($i=0; $i<$length; ++$i)  

    {  

        $random .= $string{mt_rand(0, $strlen-1)};    

    }  

    return $random;  

}



model



function check_rand($char){

$data=$this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."random WHERE randchar='$char'");

if(empty($data)){

return true;

}else {

return false;

}

}



function insert_rand($char){

$this->db->query("INSERT INTO ".UC_DBTABLEPRE."random SET randchar='$char'");

return $this->db->insert_id();

}

热点排行