feha
|
| Posted: 10/21/2002, 2:51 AM |
|
I wonder how to retrive value of the last index ID (autoincrementing and unique)
from MySQL/PHP?(Not a number of records, but value)
This I would need to use before I insert e new record.
regards
feha
www.vision.to
|
|
|
 |
lukas
|
| Posted: 10/21/2002, 4:08 AM |
|
feha
i think, you don't need this value BEFORE inserting a record. if the table is specified as autoincrementing, just insert 0 (zero) as value or do not specify this field in the sql query. then the next free increment is used.
if you use this value AFTER inserting, for example to update another table or to insert a cross reference into another table, you get this value with mysql_insert_id ([resource link_identifier]).
regards
lukas.
--
pixworx multimedia http://pixworx.ch
|
|
|
 |
feha
|
| Posted: 10/21/2002, 4:37 AM |
|
Thanks for Your answer, .-)
but the fact is that I need it.
Registration form +
I want to insert images in to mysql at one submit...
at the same time using MySQL querry as UPDATE ... not insert...
Than I need the value of index to be able to use WHERE id=... (index)
(by submiting two forms at once...)
The images have to be inserted/updated with exact index ....
regards
femi
|
|
|
 |
xbill
|
| Posted: 10/21/2002, 8:38 AM |
|
The mysql_insert_id is usually your best
approach with the auto increment feature.
You could also use a select max() on the id
to get the value. There are also more
complicated schemes to store your auto IDS
in a seperate table.
A quick possible workaround - is to break your
SQL into two calls. First do the insert-
and then get the id with mysql_insert_id.
Next- for CCS hand code a CCDLookup to do the
update/insert and pass the value of the mysql_insert_id
call. For CC- the function is dlookup.
-bill
|
|
|
 |
feha
|
| Posted: 10/21/2002, 12:54 PM |
|
Tanks xbill
U'r right...
I will use the first part of the form to let user submit reg data after that
it will show the next form if they want to upload pictures to MySQL ...
So this will put pictures in to the right record...
regards
feha
www.vision.to
|
|
|
 |
feha
|
| Posted: 10/22/2002, 6:29 AM |
|
I have fixed the problem by inserting in to forms hidden fiedl an autogenerated string with 8 charachters (very low chans to have two same values and this can be checked if this value exists... the fiedl is named as special_id )
After the form inserts data then in the afterinsert event is used this:
$db->query("UPDATE vto_pic SET e_pic_3 ='$data3' WHERE special_id='$fldspecial_id'");
I hope this tips can be useful for someone else too ?
regards
feha
www.vision.to
|
|
|
 |