saving data on two tables, the parent and child table

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
omphilesithole
Posts: 26
Joined: 2015-01-12 13:01

saving data on two tables, the parent and child table

Post by omphilesithole » 2015-03-18 10:47

I have two table and both on have the status field, a parent table called crimereport and a child table called assignreport,
so once i assign a report under that id i need to also update the parent table to change the status as assigned, what i did so far on the assignreport_dml.php under the insert function i did the following code:

$o=array('silentErrors' => true);
sql('update `crimereport` set `status`=' . ($data['status'] ) . " where `id`='".makeSafe($selected_id)."'", $o);

But its not doing anything am not sure if am doing it right or wrong please help??

Thanks

tmathew
Posts: 7
Joined: 2015-03-19 02:14

Re: saving data on two tables, the parent and child table

Post by tmathew » 2015-03-21 07:17

I too want to achieve the same. Anyone to help?

User avatar
a.gneady
Site Admin
Posts: 1287
Joined: 2012-09-27 14:46
Contact:

Re: saving data on two tables, the parent and child table

Post by a.gneady » 2015-03-22 07:11

sql('update `crimereport` set `status`=' . ($data['status'] ) . " where `id`='".makeSafe($selected_id)."'", $o);
You should change $selected_id in the where clause to the value of the lookup field ... So, assuming the lookup field is named crimereport_id, the query should be:
sql('update `crimereport` set `status`=' . ($data['status'] ) . " where `id`='".makeSafe($data['crimereport_id'])."'", $o);
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

tmathew
Posts: 7
Joined: 2015-03-19 02:14

Re: saving data on two tables, the parent and child table

Post by tmathew » 2015-03-23 12:24

Can anyone please tell me the purpose of the ' . ' (dot) used in the above syntax?
Is there some documentation which I can use for reference when writing codes in AppGini Hooks/other areas?
Is this standard PHP syntax itself? Eventhough I have programming knowledge, I am totally new to PHP/MySQL/HTML/etc (web app dev). That is why this question.

I have used a syntax similar to the bove to update a field in the same table, not in a second table. But it just displays a blank screen. I have spent almost 2 days looking for a solution to this simple issue. The syntax is
sql('update `VEHICLER2ODETAILS` set `emiamount` =` . (($data['renttoownprice'] - $data['downpaymentdefault']) * ($data['$servicerate'] / 100))/30 . " where `id`='".makeSafe($id)."'",$o);
'id' is the primary key field of the record. So I used makeSafe($id). I do not know whether this is correct or not. Hope someone will help me.

Satya Kavala
Veteran Member
Posts: 45
Joined: 2015-04-15 06:33
Location: Hyderabad
Contact:

Re: saving data on two tables, the parent and child table

Post by Satya Kavala » 2015-04-16 05:24

Hi,
$sql='update `VEHICLER2ODETAILS` set `emiamount` =` . (($data['renttoownprice'] - $data['downpaymentdefault']) * ($data['$servicerate'] / 100))/30 . " where `id`='".makeSafe($id)."';
sql($sql,$o);

here '.' (dot) operator for representing variable in php


function write_log($data)
{
$file = 'error_log.txt';
$current = file_get_contents($file);
$current .= $data."\n";
file_put_contents($file, $current);
}

Place the above function on lib.php



write_log($data['renttoownprice']);//place the line of code in .php file where the query is presented.like that take all the values if presented or not
write_log($sql);//it will displays the query, here also you can find is the query is forming perfectly or not?

once you run your application, error_log.txt file will be generated there you can see the result of the variables and query formation.

Thanks
Thanks&Regards
Satya Kavala
[email protected]

tmathew
Posts: 7
Joined: 2015-03-19 02:14

Re: saving data on two tables, the parent and child table

Post by tmathew » 2015-04-20 03:45

Thank you Satya

Satya Kavala
Veteran Member
Posts: 45
Joined: 2015-04-15 06:33
Location: Hyderabad
Contact:

Re: saving data on two tables, the parent and child table

Post by Satya Kavala » 2015-04-20 04:53

Hi,
You are most welcome tmathew .

Thanks&Regards
satya Kavala
[email protected].
+91-9951156428
Thanks&Regards
Satya Kavala
[email protected]

Post Reply