doushi1900 2016-11-10 14:52
浏览 33
已采纳

我如何在php中生成像DEL-1234这样的代码

Hey guys please i am new to php mysql, i am trying to generate a code like this DEL-12345. So if the person chooses the state Delaware in the form, it generates and stores DEL-23413 in the db on submit. DEL (First 3 letters of the state); - (Hyphen) and then 12345 (5 random numbers)...

please help

  • 写回答

2条回答 默认 最新

  • doudang4857 2016-11-10 15:02
    关注

    I would like to point you in the right direction with the code below.

    $Area = "Utah";
    $Code = strtoupper(substr($Area, 0, 3)) . "-" . (mt_rand(1000,9999));
    echo ( $Code );
    

    However, note that this code is subject to errors for example: What if the $Area variable contained a string less than 3 characters? What if the random value generated is not unique (the theory being you want it to be)

    All of this needs to be checked, by you, give it a go - we can help if needed but we wont write the whole code for you.

    Good luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数
  • ¥15 关于#线性回归#的问题:【统计】回归系数要转化为相关系数才能进行Fisher' Z转化吗(相关搜索:回归模型)
  • ¥100 使用matlab解决含分段变量的优化问题