Forums

dbloader and where statement with insertid trouble

artcode 02 Apr, 2014
Hi,

New web app with CF4 new things to learn....

I create a form with db loader action and with a where statement .

I could capture the value of a column (autoindex autoincrement field in the db) as cf_id.
But I have the value of the first row in the table ("1").

I couldn't understand how to use insertid to obtain the last value of the field in the table (like mysql last_insert_id).

I have make a request in where statement as:

$lastid=$database->insertid();


then capture the data with an echo that call $lastid.

But it couldn't pass the data.

Is it possible to have some hints about the sintax that I've to use?

Thanks in advance.

bye
fede
GreyHead 03 Apr, 2014
Hi fede,

I'm sorry but I don't understand what you are trying to do here?

Please see this FAQ if you need to know the ID of a saved record.

Bob
artcode 03 Apr, 2014
I try to explain better, thanks for your answer.
I need to obtain last id of a field cf_id in a table, then use the value +1 as counter.
like http://www.chronoengine.com/forums/posts/t10525/p10525.html in CF4.

bye
fede
artcode 08 Apr, 2014
I create a form with db loader action and with a where statement .

I could capture the value of a column (autoindex autoincrement field in the db) as cf_id.
But I have the value of the first row in the table ("1").

and this is ok.

I use:
cf_id<?php echo $form->data('cf_id']:?>


the "only" sintax that return me a value.... (in the where statement of the db loader action)

I need to obtain the last value in the last record ( the last row).

solution one:
If I try to sort the data with ORDER BY i couldn't find the correct sintax.

In the help of the db loader action:

-You can order the results and so control which record will be returned, use "ORDER BY" word in the WHERE box. e. g. ORDER by 'id'



I had try to add the "Order by" that should be DESC without success.

solution two:
I had try also to count the row but I didn't find a correct sintax that returns me data.

I search in the forum but didn't find case of use a row count in the where staement in dbloader.

bye
fede
artcode 08 Apr, 2014
errata:
cf_id<?php echo $form->data('cf_id'];?>

bye
fede
artcode 08 Apr, 2014
Answer
find the solution:
cf_id<?php echo $form->data('cf_id'];?> ORDER BY 'cf_id' DESC

IT MUST BE ALL IN THE SAME LINE

could'nt use also in the first part:
'cf_id'=

OR
cf_id=


thanks and bye
fede
This topic is locked and no more replies can be posted.