生成唯一订单号 [英] Generating Unique Order Number
本文介绍了生成唯一订单号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试通过Graph API上传Facebook页面的封面图片,但是一旦它更新就会显示在时间轴上。
I am trying to upload the cover image of a Facebook Page via Graph API, But it appears on the Timeline once its updated.
我使用以下字符串检查我的订单号是否是唯一的
I am using the following string to check of my order number is unique
$unique_order_number = strtoupper(substr(md5(microtime()), 0, 8))
现在我想确保这个号码不会被任何其他订单占用,一个循环while或do-while循环来检查赋值。
Now i want to just make sure that this number is not taken by any other order and wanna use a loop while or do-while loop to check the assignment.
public function __unique_order_no() {
$order_no_exisits = $this->Order->find('first', array('order_no' => $unique_order_number));
while (!empty($order_no_exisits)) {
$unique_order_number = strtoupper(substr(md5(microtime()), 0, 8));
$order_no_exisits = $this->Order->find('first', array('order_no' => $unique_order_number));
debug($order_no_exisits);
}
debug($order_no_exisits);
}
如何使用While循环运行它,直到我得到一个唯一的数字?
How can i use a While Loop to run it till i get a unique number?
推荐答案
while (!empty($order_no_exisits)) {
$unique_order_number = strtoupper(substr(md5(microtime()), 0, 8));
if(!$this->Order->find('first', array('order_no' => $unique_order_number)))
exit;
}
这篇关于生成唯一订单号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文