读书人

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

发布时间: 2012-09-02 21:00:34 作者: rapoo

随机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();

}

读书人网 >Web前端

热点推荐