Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

edit code after save

Locked
johan
Posts: 392
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium

edit code after save

Unread post by johan »

Hi,

I'm trying to make some code to run after save.

Code: Select all

if('#clone#' == '1' or '#recordID#' == '-1'){     //-- this is a new record

   nuRunQuery("INSERT INTO fac_counter (tc_text) VALUES ('1')");

   $s  = "UPDATE facturatie SET fac_ogm2 = '" . mysql_insert_id() . "' ";
   $s .= "WHERE fac_id = '#newID#'";

   nuRunQuery($s);


$c = nuRunQuery("select mod(concat(fac_ogm1, fac_ogm2, fac_ogm3),97) from facturatie where fac_id = '#newID#'");

If ($c =='0'){

nuRunQuery("update facturatie set fac_ogm4 = '97' where fac_id = '#newID#'");

}else{

nuRunQuery("update facturatie set fac_ogm4 = (select mod(concat(fac_ogm1, fac_ogm2,'00'),97))where fac_id = '#newID#'");

}

$t = nuRunQuery("select fac_ogm4 from facturatie where fac_id = '#newID#'");

if ($t <'10') {

nuRunQuery("update facturatie set fac_nummer = concat('+++',fac_ogm1,'/', fac_ogm2,'/',fac_ogm3,'0',fac_ogm4,'+++') where fac_id = '#newID#'");

} else {

nuRunQuery("update facturatie set fac_nummer = concat('+++',fac_ogm1,'/', fac_ogm2,'/',fac_ogm3,fac_ogm4,'+++') where fac_id = '#newID#'");
}
}



This is causing me some problems. I've first tried it in (procedure) so i could see easier what it's doing. There the update worked fine (exept the ifs).

Problem is that if I echo $c (or something else) i get #resourceID# 38 and not the integer I'm expecting. So the if won't work. I think / hope the rest of my sql / code is ok.



Other problem is that the 2 last figures is a code generated by mod(),97). This have to be 2 digits. When te result is < 10 I need 01, 02, .... Now I've tried to solve it with if.... but is there a better sollution.


Thanks a lot.

Johan
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: edit code after save

Unread post by admin »

Johan,

try this

Code: Select all

$c = nuRunQuery("select mod(concat(fac_ogm1, fac_ogm2, fac_ogm3),97) from facturatie where fac_id = '#newID#'");

$row = db_fetch_row($c);  //-- you could use mysql_fetch_row($c) 

If ($row[0] =='0'){  ....

This might explain it better http://php.net/manual/en/function.mysql-fetch-row.php

Steven
johan
Posts: 392
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium

Re: edit code after save

Unread post by johan »

Steven,

thanks again,
Johan
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: edit code after save

Unread post by admin »

.
Locked