Forums: [SOLVED] sql query error - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

[SOLVED] sql query error Rate Topic: -----

#1 User is online   Catalin 

  • Member
  • PipPip
  • Group: Members
  • Posts: 19
  • Joined: 11-February 19

Posted 13 March 2019 - 10:24 PM

Hi,

I am trying to use a query which updates a field in the latest added record in a table. I have added this in the After record added events(Add page).

$sql = "SELECT @last_id := MAX(mid) FROM malp;
UPDATE malp SET poli = CONCAT('Start:', `mxds`, ' ', `mxde`, ' ', `emit`) WHERE mid=@last_id;";
CustomQuery($sql);

While the query works fine in phpmyadmin and the dbmanager I'm using, in phprunner it throws errors. The update works fine but I don't want to update all rows when adding a new record.

I guess that there is a particular syntax here(or I'm particularly dumb) but anyway, any help is greatly appreciated. :blink:

Thanks.

C
0

#2 User is online   Catalin 

  • Member
  • PipPip
  • Group: Members
  • Posts: 19
  • Joined: 11-February 19

Posted 14 March 2019 - 08:38 AM

View PostCatalin, on 14 March 2019 - 12:24 AM, said:

Hi,

I am trying to use a query which updates a field in the latest added record in a table. I have added this in the After record added events(Add page).

$sql = "SELECT @last_id := MAX(mid) FROM malp;
UPDATE malp SET poli = CONCAT('Start:', `mxds`, ' ', `mxde`, ' ', `emit`) WHERE mid=@last_id;";
CustomQuery($sql);

While the query works fine in phpmyadmin and the dbmanager I'm using, in phprunner it throws errors. The update works fine but I don't want to update all rows when adding a new record.

I guess that there is a particular syntax here(or I'm particularly dumb) but anyway, any help is greatly appreciated. :blink:

Thanks.

C


This one works(i.e. update a target field in the latest added record).

UPDATE malp SET poli = CONCAT('Start:', `mxds`, ' ', `mxde`, ' ', `emit`) ORDER BY mid DESC
LIMIT 1;
0

#3 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16361
  • Joined: 03-February 03
  • Gender:Male

Posted 15 March 2019 - 04:33 PM

If you check AfterAdd documentation event you will see that you already have access to new ID, no need to perform an extra SQL Query:
https://xlinesoft.co...ecord_added.htm

Assuming that "mid" is your key column you can access its value as $keys["mid"]
Best regards,
Sergey Kornilov
0

#4 User is online   Catalin 

  • Member
  • PipPip
  • Group: Members
  • Posts: 19
  • Joined: 11-February 19

Posted 17 March 2019 - 06:44 AM

View Postadmin, on 15 March 2019 - 06:33 PM, said:

If you check AfterAdd documentation event you will see that you already have access to new ID, no need to perform an extra SQL Query:
https://xlinesoft.co...ecord_added.htm

Assuming that "mid" is your key column you can access its value as $keys["mid"]


Cool, thank you Sergey.
0

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users