使用自动增量创建唯一的订单号。 [英] Creating a unique order number using auto increment.

查看:137
本文介绍了使用自动增量创建唯一的订单号。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在这个网站上有一些好运,所以我回来了,我必须重复我是一个初学者。


我遇到一些问题,需要掌握正确的技术来管理变量并在客户订单中添加一个唯一的订单号。


我的订单有4个阶段。


第1阶段涉及用户根据自己的需要选择链接。然后该链接设置2个变量。 $ type和$ fault基于他们选择的链接。


在第2阶段我用过


[PHP]

<?php

$ type = $ _GET [''$ type''];

$ fault = $ _GET [''$ fault'' ];

?>


[/ PHP]


并回复这些细节订单表格(在一个只读的输入框中,使他们更方便发送,对我来说也很好)这个工作正常。


如果我使用会话,我还需要这样做处理我的变量。


在第2阶段,用户必须在表格上填写他们的详细信息并提交。我用post作为动作。


在第3阶段,所有细节都正确显示。


我的问题确实存在。

我想添加一个唯一的订单号,我已经为第一个订单做了这个,但是无法获得订单号然后自动递增。我已经设置了所有的表格,并且很好地连接它们。


这个代码如下:


[PHP]< ?php

$ sql =" SELECT * FROM i_counter" ;; //此表管理递增计数器。它包含一行名为cnt。

$ result = mysql_query($ sql,$ db);

$ row = mysql_fetch_array($ result);

$ cnt = $ row [" cnt"];

$ cnt ++;

$ order_id =" IPRD" 。 $ CNT; //使用公司ID为订单号添加前缀


//更新订单ID的计数器


$ sql =" UPDATE i_counter SET cnt = $ cnt" ;;

$ result = mysql_query($ sql);


//添加新的临时数据库条目


$ sql =" INSERT INTO i_orders(id,ordernumber)VALUES('''',''$ order_id'')" ;;

$ result = mysql_query($ sql);

?>

[/ PHP]


代码目前位于文件的开头在2个包含语句之后,一个用于数据库连接,另一个用于页面标题。


虽然我可能会更快地参加会议,但我真正需要帮助的是自动增加顺序数量。


非常感谢

Hi,

I have had some good fortune on this site so I am back and I must iterate I am a beginer.

I am having some problems getting to grips with the right technique to manage variables and adding a unique order number to a customer order form.

I have 4 stages to my order form.

Stage 1 involves the user selecting a link based on what they want. The link then sets 2 variables. $type and $fault based on the link they have chosen.

In stage 2 I have used

[PHP]
<?php
$type = $_GET[''$type''];
$fault = $_GET[''$fault''];
?>

[/PHP]


and echo these details on the order form (in a read only input box to make sending them on easier, well for me anyway) and this works fine.

Would I still need to do this if I used sessions to handle my variables.

In stage 2 the user then has to fill in their details on a form and submit the from. I have used post as the action.

In stage 3 all the details are displayed correctly.

It is here where my problem really exists.

I want to add a unique order number, I have done this for the first order but cant get the order number to then auto increment. I have all the tables set up and am connecting to them fine.

The code for this is as follows

[PHP] <?php
$sql="SELECT * FROM i_counter"; // This table manages the incrementing counter. It contains 1 row called cnt.
$result=mysql_query($sql,$db);
$row = mysql_fetch_array($result);
$cnt= $row["cnt"];
$cnt++;
$order_id="IPRD" . $cnt; //prefixes the order number with company ID

// Update counter for order id''s

$sql = "UPDATE i_counter SET cnt = $cnt";
$result = mysql_query($sql);

// Add a new temp database entry

$sql = "INSERT INTO i_orders (id, ordernumber) VALUES ('''', ''$order_id'')";
$result = mysql_query($sql);
?>
[/PHP]

The code is currently sitting at the start of my file just after 2 include statements, one for db connection and the other for the page header.

Though I will probably more on to sessions soon the issue I really need help with is the auto incremneting order number.

Many thanks

推荐答案

类型和


基于他们选择的链接。


在第二阶段,我使用了


[PHP]

&l t;?php
fault based on the link they have chosen.

In stage 2 I have used

[PHP]
<?php


type =


这篇关于使用自动增量创建唯一的订单号。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆