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_q uery($sql,$db);
$row = mysql_fetch_arr ay($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($sq l);
// Add a new temp database entry
$sql = "INSERT INTO i_orders (id, ordernumber) VALUES ('', '$order_id')";
$result = mysql_query($sq l);
?>
[/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
12 28458
[quote=badvoc]// Update counter for order id's
$sql = "UPDATE i_counter SET cnt = $cnt";
$result = mysql_query($sq l);
[/PHP]
I seem to have solved this by using insert into instead of update.
But thanks if you have stopped by to help.
kovik 1,044
Recognized Expert Top Contributor
Why would you use a separate table for a counter? Have you ever heard of AUTO_INCREMENT?
pbmods 5,821
Recognized Expert Expert
Heya, Badvoc.
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Please don't use the phrase 'Help!!' in your thread title in the future. It violates the, Posting Guidelines, makes more work for me and in general actually turns people *off* to your thread before they've even read it.
Sorry about the title, I did try to add some detail but now see that it is annoying to see help in titles.
I'm sure I'll be back.
Thanks
Why would you use a separate table for a counter? Have you ever heard of AUTO_INCREMENT?
Yeah I have the cnt set to auto incremant. i am using a seperate table as I couldn't get it to work so tried it as an option and it is still there.
I also want to store the actual order number which is prefixed with a 4 letters thus making it different to the id.
I suppose now its working I could just go back to the one table and use the id column and auto increment that..
Cheers
kovik 1,044
Recognized Expert Top Contributor
You could also use the regular table and get the latest id from that table, then continue your incrementing.
pbmods 5,821
Recognized Expert Expert
Heya, Badvoc.
Consider separating your ID from your ID prefix.
For example, if you have to items with these IDs:
Consider separating the two parts: - id=2, prefix=ffr
- id=3, prefix=mcv
You can easily format the 'human-readable' version of the id on the PHP side (or you can even index it as a separate field on the MySQL table itself). Plus, AUTO_INCREMENT just works, and you have a separate field dedicated to storing item prefixes, which makes searching faster.
You also may want to consider mapping a many-to-one relationship between the two data: -
CREATE TABLE `items`( `itemid` INT ZEROFILL UNSIGNED ... AUTO_INCREMENT, `prefixid` INT UNSIGNED ... );
-
-
CREATE TABLE `prefixes`( `prefixid` INT UNSIGNED ... AUTO_INCREMENT, `prefix` CHAR(3) NOT NULL UNIQUE ... );
-
After messing about with my design I have lost the section where I generate my order number so I am starting again and using the one table, as suggested, with an auto incrementing column to generate the ID. I then have an order_number column that stores the full order number.
I am unsure of how to call the last id used and add one to it to create the next value. I know about the auto increment feature but as I am not using that number directly as an order number I am unsure of how to do it.
The format for my order number is ABCD0000ID
ABCD are the initials to be placed in front of the every order number.
0000 are 4 zeros I added as I stumbled accross the code by chance and thought I would add it.
ID is the auto incremented number from the table.
The way I see it is that I have to get the last known value for ID then increase it by one and include the new ID when creating the order number and re submit the new ID to the table. Is there an easier way it can be done using the auto increment to better use.
Cheers
Right I seem to have done it again. I have sort out the auto increment an am using 1 table.
The issue i have is with my 4 zeros. I want the order number to be made up of 4 letters and 6 numbers, so the 4 zeros are included in the number not just added to it as I have done.
[PHP] $order_id="IPRD " .sprintf("%04d" , $order_id) . $cnt;[/PHP]
This is what I have but am sure it was different to this yesterday.
Any ideas?
Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: MrBoom |
last post by:
Does using uniqid seem a reasonable way of generating a unique row
identifyer in a db table? It's *highly* unlikely that two ids are
going to be generated in the same microsecond, but if they are,
setting lcg as true should eliminate any problems I'd have thought.
Anyway, these are my thoughts, do people agree?
|
by: margraft |
last post by:
Hello,
I'm somewhat of a newbie and I need to create a view with a column
that is not derived from any other tables. What I want is for this
field to be an auto-increment field or some kind of UID. Can anyone
quickly tell me how to do this.
Here is my dilemma. I need to pull data from a unique data set from a
table which does not have a primary key, and none exists in its data.
Please tell me how to put this data in a view(or...
|
by: August1 |
last post by:
A handful of articles have been posted requesting information on how
to use these functions in addition to the time() function as the seed
to generate unique groups (sets) of numbers - each group consisting of
6 numbers - with a total of 50 groups of numbers.
A well-known girl that some publishing companies use to provide
introductory level textbooks to various Junior Colleges in the U.S.,
not surprisngly, asks for this same exact...
|
by: Yannick Turgeon |
last post by:
Hello all,
I'm using SS2K on W2k.
I'v got a table say, humm, "Orders" with two fields in the PK:
OrderDate and CustomerID. I would like to add an "ID" column which
would be auto-increment (and would be the new PK). But, I would really
like to have orders with the oldest OrderDate having the smallest ID
number and, for a same OrderDate, I'd to have the smallest CustomerID
first. So my question is:
|
by: Chris |
last post by:
Before I started to create table, etc to track unique form field record
number assigments I thought I'd check to see if there is now a better way to
do this in .NET.
I have a parent form (table) and children form (table). Relationship equals
one to many. I'd like to auto number the fields accordingly and traditionaly
I assign a unique number based on a table value that I retrieve + 1.
i.e.
Parent record field value = 1
Children record...
| |
by: S.Dickson |
last post by:
I had an access database that i use as an ordering system. I have a
form for entering customer details. When i add a new customer on the
form the customer number is an auto number that appears when i type in
the details.
I have just moved over to mysql server with access as the front end. I
have setup the sql tables with the customer number as autonumber.
When i go into the form and add a new customer it does not generate the
|
by: crazy123 |
last post by:
Please guide me as how do can we create a aut generated number...
I have created a database. I am giving each name in the database entry a unique ID
I want the Unique ID to be auto generated when I want to add an entry in the database in an increment fashion
Do let me know ur views and the code that works...I m in urgent need of it...........
thanks a lot
|
by: Matuag |
last post by:
How can we create a unique and non-editable ID from client's first and
last name?
eg.: SmitJ1 for John Smith
Matuag
|
by: Claire |
last post by:
Hi,
I can imagine this question has been brought up before but I've spent all
morning trying to find what I need on google without success.
My application sits on Mysql or MS sql server engines and to date I've just
been using auto-incremental int64 fields to generate my RecID field.
I know that in the future the database will need to support multiple sites,
so theres also a SiteID field in there too.
example table ABC
Primary Key =...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |