Updating field with most recent order

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
lmire
Posts: 10
Joined: 2020-02-27 13:53

Updating field with most recent order

Post by lmire » 2020-02-27 14:30

I'm trying to figure out how to update a field automatically to include the date of the most recent order.

I have two tables ACCOUNTS and ORDERS.

The ORDERS table has a FIELD named LastOrderDate which automatically date&time stamps an entry into ORDERS. (<%%creationDateTime%%>)

Does anyone know how I can update the LastOrderDate field in the ACCOUNTS table to show the most recent entry from the ORDERS table.

I've tried using multiple SQL statements in the calculated field tab, but I can't seem to figure out the correct command. Any help would be appreciated.
here.jpg
here.jpg (36.32 KiB) Viewed 32780 times
here.jpg
here.jpg (36.32 KiB) Viewed 32780 times
Attachments
here1.jpg
here1.jpg (32.02 KiB) Viewed 32780 times

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Updating field with most recent order

Post by D Oliveira » 2020-02-27 15:17

hooks/orders.php

after insert and after update functions, paste this code:

Code: Select all


sql(“UPDATE accounts SET ‘LastOrderDate’ = ‘{$data[‘LastOrderDate’]}’ WHERE ‘login’ = ‘{$data[‘account’]’”, $eo);

this code is case sensitive so make the appropriate changes :)

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-27 16:34

Hello. Thank you for the response.

This is the edited code I pasted into orders.php
php.png
php.png (7.86 KiB) Viewed 32766 times
This is the error I'm getting when trying to view orders.php

Parse error: in C:\xampp\htdocs\test\hooks\Orders.php on line 239

I've tried different variations of uppercase and lowercase. Is my syntax correct?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Updating field with most recent order

Post by jsetzer » 2020-02-27 17:13

Maybe there is a problem with the qoutes?

A couple of days ago I have published a short explanation here:

https://appgini.bizzworxx.de/appgini/qu ... -commands/
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Updating field with most recent order

Post by pbottcher » 2020-02-27 17:56

Agree with Jan,
Try

Code: Select all

sql("UPDATE accounts SET `LastOrderDate` = '".$data['LastOrderDate']}."' WHERE `login` = '".$data['account']."'", $eo);
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-27 19:10

pböttcher wrote:
2020-02-27 17:56
Agree with Jan,
Try

Code: Select all

sql("UPDATE accounts SET `LastOrderDate` = '".$data['LastOrderDate']}."' WHERE `login` = '".$data['account']."'", $eo);
sql("UPDATE accounts SET `LastOrderDate` = '".$data['LastOrderDate']}."' WHERE `login` = '".$data['account']."'", $eo);
returns
Parse error: syntax error, unexpected '}', expecting ')'

sql("UPDATE accounts SET `LastOrderDate` = '".$data['LastOrderDate'])."' WHERE `login` = '".$data['account']."'", $eo);
returns
Parse error: syntax error, unexpected ','

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Updating field with most recent order

Post by pbottcher » 2020-02-27 19:41

sql("UPDATE accounts SET `LastOrderDate` = '".$data['LastOrderDate']."' WHERE `login` = '".$data['account']."'", $eo);
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-27 20:20

Thank you for the help guys. No more parsing errors, but the LastOrderDate column still isn't being updated on the Accounts page. Any ideas?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Updating field with most recent order

Post by pbottcher » 2020-02-27 20:33

Hi,

can you post your tabledefinitions? Are you using any lookups? Are the accounts login and the Orders Account the same?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-27 20:54

pböttcher wrote:
2020-02-27 20:33
Hi,

can you post your tabledefinitions? Are you using any lookups? Are the accounts login and the Orders Account the same?



Yes, I'm using lookups. I should have mentioned that initially.



lookup.jpg
lookup.jpg (52.83 KiB) Viewed 32745 times

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-27 21:01

TABLE
Orders
FIELD
Account

Lookup

TABLE
Accounts
FIELD
Login

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Updating field with most recent order

Post by pbottcher » 2020-02-27 21:18

sql("UPDATE accounts SET `LastOrderDate` = '".$data['LastOrderDate']."' WHERE `id` = '".$data['account']."'", $eo);

assuming that id is the PK.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-27 21:42

Yes, id is the Primary Key.

I dropped the DB and created from scratch. Reinserted the code into Orders.php.

LastOrderDate still isn't being populated on the Accounts page.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Updating field with most recent order

Post by D Oliveira » 2020-02-28 01:57

Code: Select all

sql("UPDATE Accounts SET LastOrderDate = '{$data['LastOrderDate']}' WHERE Login = '{$data['Account']}'", $eo);

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-28 02:14

D Oliveira wrote:
2020-02-28 01:57

Code: Select all

sql("UPDATE Accounts SET LastOrderDate = '{$data['LastOrderDate']}' WHERE Login = '{$data['Account']}'", $eo);
It still isn't posting anything to the Accounts page.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Updating field with most recent order

Post by jsetzer » 2020-02-28 06:05

Maybe you should var_dump($data['Account']); exit();

...and check if that really matches any Login.

If your where clause does not find any record, nothing will be updated.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Updating field with most recent order

Post by pbottcher » 2020-02-28 09:36

Hi,

please post the fields of your database, otherwise it is only stumling in the dark. Please with upper/lowercase.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-28 17:33

pböttcher wrote:
2020-02-28 09:36
Hi,

please post the fields of your database, otherwise it is only stumling in the dark. Please with upper/lowercase.
myfields.jpg
myfields.jpg (80.17 KiB) Viewed 32691 times
https://drive.google.com/open?id=1V_RV9 ... r0eEfxHHYU

Here is the link to my APX file. It's a very simple DB.

I am also willing to pay for paid customization, if anyone here is interested. I have contacted the official support channel for paid customization, but he is unfortunately too busy to accept any additional requests at the moment.

I need 3 or 4 minor changes made, not a large project.
Last edited by lmire on 2020-02-28 17:34, edited 1 time in total.

lmire
Posts: 10
Joined: 2020-02-27 13:53

Re: Updating field with most recent order

Post by lmire » 2020-02-28 17:33

jsetzer wrote:
2020-02-28 06:05
Maybe you should var_dump($data['Account']); exit();

...and check if that really matches any Login.

If your where clause does not find any record, nothing will be updated.
Thank you for your help, but I do not understand what this means. I am requesting paid support.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Updating field with most recent order

Post by D Oliveira » 2020-02-28 20:04

lmire wrote:
2020-02-28 17:33
pböttcher wrote:
2020-02-28 09:36
Hi,

please post the fields of your database, otherwise it is only stumling in the dark. Please with upper/lowercase.
myfields.jpg

https://drive.google.com/open?id=1V_RV9 ... r0eEfxHHYU

Here is the link to my APX file. It's a very simple DB.

I am also willing to pay for paid customization, if anyone here is interested. I have contacted the official support channel for paid customization, but he is unfortunately too busy to accept any additional requests at the moment.

I need 3 or 4 minor changes made, not a large project.
last try

Code: Select all

sql("UPDATE Accounts SET LastOrderDate = '{$data['LastOrderDate']}' WHERE id = '{$data['Account']}'", $eo);

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Updating field with most recent order

Post by D Oliveira » 2020-02-28 20:05

lmire wrote:
2020-02-27 21:01
TABLE
Orders
FIELD
Account

Lookup

TABLE
Accounts
FIELD
Login
this would be the right structure:

TABLE
Orders
FIELD
Account

Lookup

TABLE
Accounts
FIELD
id

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Updating field with most recent order

Post by pbottcher » 2020-03-01 16:07

ok, we clarified this offline.

Result.

Code: Select all

sqlvalue("UPDATE Accounts SET `Balance` = Balance-'".$new_balance."' WHERE `id` = '".$data['Account']."'");
works fine.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply