matthewbonline — 2011-09-22T08:01:33-04:00 — #1
I want to enter a code into a MySQL database. I want it to start and continue like this:
I will code it to always display "AGPS-"
In the MySQL database I will store 1000000. Then auto-increment it.
The problem is with coding the retrieval of the code:
This does not work:
The code $ThisVendorTxCode = "AGPS-"$row["vendor"];
This code works:
$ThisVendorTxCode = "AGPS-";
but it does not get the vendor code because the ";" ends the request. But without it it says there is an error in the code.
How do I get the AGPS- at the start followed by what is in the database? How do I code it?
gvre — 2011-09-22T08:11:18-04:00 — #2
You should use the concatenation operator. Try "AGPS-" . $row['vendor'];
matthewbonline — 2011-09-22T09:17:09-04:00 — #3
OK - thanks for that. it is working well now.
But my problem now is i get this error my PHPMyAdmin
1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
how do i auto-increment more than one?
starlion — 2011-09-22T09:20:19-04:00 — #4
Why do you need to auto-increment more than one?
guido2004 — 2011-09-22T09:20:56-04:00 — #5
You can't. Why would you want more than one autoincrement column in one table?
matthewbonline — 2011-09-22T09:44:54-04:00 — #6
c_ankerstjerne — 2011-09-22T10:11:46-04:00 — #7
You can also solve this on database level, which should be more efficient:
If you auto-increment on column vendor:
SELECT CONCAT("AGPS-", vendor) AS vendor
If you auto-increment on column id, and where id equals the last digits in vendor:
SELECT CONCAT("AGPS-", 1000000 + id) AS vendor
Alternately (likely slower, but also more versatile if you can't use simple addition):
SELECT CONCAT("AGPS-1", LPAD(id, 6, "000000")) AS vendor