473,396 Members | 2,089 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,396 software developers and data experts.

accessing auto increment in database through code

hi all

i need a help
here,i want to increment an number in database through php code
without using auto increment key in database.it must be incremented automatically by inserting the values in front page..
can anyone help meeeee plz
Apr 4 '07 #1
1 2350
Atli
5,058 Expert 4TB
You could query the database for the highest number in the column you want to increment and then manually increment that number before inserting the data.

[PHP]
/* -- Table structure --
CREATE TABLE Table (
idcol INT NOT NULL Primary Key,
data VARCHAR(255) NOT NULL
)
*/
$RES = mysql_query("SELECT MAX(idcol) as 'Max' FROM Table");

if(mysql_num_rows($RES) == 1) {
$ROW = mysql_fetch_assoc($RES);
$inc = $ROW['Max'] + 1;

$RES2 = mysql_query("INSERT INTO Table(idcol, data) VALUES($inc, 'mydata')";

if(!!$RES2) {
echo "Inserted";
}
else {
echo "Failed";
}
}

[/PHP]

Why don't you want to use Auto_increment tho?
Apr 4 '07 #2

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

Similar topics

2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Paulovič Michal | last post by:
hi all, I have problem with SERIAL field type (or sequence functionality). I have table with three columns - ID, IDS, NAME. I want auto-increment IDS grouped by ID. Example: 1, 1, Ferdo 1, 2,...
2
by: john | last post by:
Is it true that if I split my access database in backend and frontend and I implement custom auto increment for the ID fields, that my database is ready to be used in a multi-user environment? I...
13
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...
1
by: rhepsi | last post by:
hii all, i have created a database with a table with number of fields....in msaccess ive set primary key as SNo: and its datatype as auto number... How to set the auto increment ???? ...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
2
by: markcarroll | last post by:
My company has a database on SQL server. I am tyring to make an access interface that will make a lot of things easier. I cannot change the database structure or the field types. I am trying to...
3
by: paulyXvpf | last post by:
Hello, all... Just finished a handy tutorial that has helped me understand how to auto increment and post to a web page... but its only a Web User Control passing values from VB.NET method...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
agi2029
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,...

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.