佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1113|回复: 6

要怎样设置呢?A00001, A00002... A00010

[复制链接]
发表于 2-4-2010 05:13 PM | 显示全部楼层 |阅读模式
Hi,
我想问问,我要怎样设置呢?
我用 php n mysql
我要怎样auto generate 这样的agent id呢?
A00001, A00002 ... A00010
谢谢回答
回复

使用道具 举报


ADVERTISEMENT

发表于 2-4-2010 05:44 PM | 显示全部楼层
本帖最后由 雷克斯R 于 2-4-2010 05:46 PM 编辑

給你參考

function generate_agent_id(){
    $sql = "select agent_id from agent order by agent_id desc limit 1";
        $result = mysql_query($sql);
            if (mysql_num_rows($result) > 0){            
                $agent_id = mysql_result($result, 0,"agent_id" );
                $agent_id = substr($agent_id, 1);
                $agent_id = (int) $agent_id;
                $agent_id++;               
                $n = 5 - strlen($agent_id);
                $agent_id = "A" . str_repeat("0", $n) . $agent_id;                        
            } else {
                $agent_id = "A00001";
            }
    return $agent_id;                        
}
回复

使用道具 举报

 楼主| 发表于 2-4-2010 07:17 PM | 显示全部楼层
回复 2# 雷克斯R

先谢谢你
想问下,如果下一个agent,那他的agent id是不是自动成为A00002呢?
回复

使用道具 举报

发表于 3-4-2010 06:51 PM | 显示全部楼层
the best way of course is using "database sequence number" lah...high recommanded for web based system...!!

simple reason is because web based system will facing multiple users access concurrently...thus it may raised some data integrity issue.

like above function...this function is query the latest agent number from the member table then add one in order to create new agent number...plz imagine that if more than one member get the same latest agent number... then the next new agent number will be share by all those member lor...this is the main problem for above problem...
回复

使用道具 举报

 楼主| 发表于 3-4-2010 11:18 PM | 显示全部楼层
回复 4# kkwpms99

说的也有道理
所以有任何意见呢?
要怎样做呢?
回复

使用道具 举报

发表于 4-4-2010 03:32 AM | 显示全部楼层
Juz sory i reply by using english word first...

Firstly, i m not familiar with mySQL script..most of the time i m using ORACLE database.

so in Oracle DB, it can let u to create SEQUENCE object. after the object created then u can call use the object by using SQL script. this link for ur reference:  http://www.techonthenet.com/oracle/sequences.php

but the object only can generate numeric number in sequence. thus, u can call the object to create new number to u first...then temporarily store in an variable. after that, convert the number to string and format it to ur desire pattern.

this got one advantage is to ensure data integrity. if u interest on y this can ensure data is unique, u need to find the answer urself. it is difficult to let me explain to u here...but the concept actually very simple but difficult to write it out since i m not really good in writing...

above link can help u understand better...
回复

使用道具 举报

Follow Us
 楼主| 发表于 4-4-2010 11:10 AM | 显示全部楼层
回复 6# kkwpms99

你回复英文没有问题
但只怕版主看到会扣分而已
但还是要谢谢你哦
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 26-11-2025 02:06 PM , Processed in 0.121412 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表