473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Create unique value

I am trying to create a unique index value when uploading records to my table. In the past, I have used the autoincrement option in my MySQL database, but for this table I want to create the index value based on several differant variables.

So far this is what I have:

[PHP]$lotid=$nameid_$date_$recordnumer[/PHP]

What I want to do is say user 014 is uploadin thier first record of the day on 2006-12-01 the script would be (and I know that this is not necessarily what the code would look like, but you get the idea):

[PHP]$nameid=014
$date=2006-12-01
$recordnumber=0001

$lotid=014_2006-12-01_0001[/PHP]

However, if they have already posted a record on that day and recordnumber 0001 is used, I want $recordnumber to echo 0002 and so on.

Any ideas?
Dec 14 '06 #1
1 1988
ronverdonk
4,258 Expert 4TB
Get the highest stored sequence number by performing a SELECT LIKE and, depending on the retrieved value, increment the retrieved record number or, if there is none, set it to 001.
Expand|Select|Wrap|Line Numbers
  1. SELECT SUBSTR(lotid,16) AS seq 
  2.        FROM a 
  3.        WHERE lotid like '2006-10-25_014_%' 
  4.        ORDER BY seq DESC 
  5.        LIMIT 1;
Ronald :cool:
Dec 14 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: kevin parks | last post by:
hi. I've been banging my head against this one a while and have asked around, and i am throwing this one out there in the hopes that some one can shed some light on what has turned out to be a...
7
by: kackson | last post by:
Hi. I created a simple view with the following statements: CREATE VIEW dbo.VIEW1 AS SELECT dbo.VIEW_ALL.ID, dbo.VIEW_ALL.Code, Another.dbo.OTHER_VIEW.Label as SpecialCode FROM ...
7
by: Wolfgang Kreuzer | last post by:
Hello all, I have two tables - Projects and ProjectStruct Table Projects contains master records of the projects, ProjectStruct allows to define a project herarchie and contains the fields...
1
by: Jenny | last post by:
Hi, Can I create an array of tags by assigning same name to these tags? For example, I have two <p> tags with the same name t1. But document.all.b.value=document.all.t.length does not...
24
by: flkeyman | last post by:
Work in legal office. Trying to create solid designed database structure. This is list of tables w/fields and primary keys. Any comments/advice greatly appreciated. tbl-Defendants CaseNumber...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
3
by: zufie | last post by:
I want to use SQL code to Create a Table & Provide a Default Value for Each Column. Here is the code I am using: CREATE TABLE customer (First_Name char(50), Last_Name char(50), Address...
3
by: anudu | last post by:
hi , I am developing a system using javascripts and ajax. I am retrieving data from database and bind them in an html table. I am using a for loop to do this. This table has one column of html...
3
by: askohen | last post by:
I have this CREATE TABLE statement: CREATE TABLE howto ( id INT IDENTITY(1,1) PRIMARY KEY, title VARCHAR(100) UNIQUE NOT NULL, url VARCHAR(20) UNIQUE NOT NULL, order_on_homepage SMALLINT...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.