This topic is locked
[SOLVED]

 Master / Detail

11/12/2012 8:44:42 AM
PHPRunner General questions
I
Ivan van Oosterhout author

Hello
I am confussed and cant go on, maybe somebody can explain me.
I have a Master tabel (table: planningsysteem), i have a checkbox (klaar_exp). I want to close this order but...
The Header/Details (Table: header)rows have also a checkbox (Done) and have to be all closed before you can close the order in the mastertable.
How can i do this, or validate?
Made a drawing:


Many thanks,

C
cgphp 11/12/2012

In the "Before record updated" event, check if the field values of detail records are closed. Here it is similar code: http://xlinesoft.com/phprunner/docs/before_deleting_a_record_check_if_related_records_exist.htm

I
Ivan van Oosterhout author 11/14/2012

Hi Christian,
I use this code now to check if my query is correct but it gives me always true.. Maybe you see why?
I have made 2 rows in the header, i activated 1 checkbox to checked and one is not checked. It still gives me true

If i make the checkboxes of the 2 rows unchecked it still gives me true.
I think it does not check the complete array, do you see the problem?
function BeforeEdit($values,$where,$oldvalues,$keys,$message,$inline,$pageObject)
global $dal;

$tblOrder = $dal->Table("header");

$rs = $tblOrder->Query("PlanID=".$oldvalues["aanmeldnum"],"");

$data = db_fetch_array($rs);
if($data["Done"]==0) {

echo "<script>alert('FALSE')</script>";

return false;
}

else {

echo "<script>alert('TRUE')</script>";
return true;

}

C
cgphp 11/14/2012

I'm assuming the query below returns more than one result:

global $dal;

$tblOrder = $dal->Table("header");

$rs = $tblOrder->Query("PlanID=".$oldvalues["aanmeldnum"],"");
while($data = db_fetch_array($rs))

{

if($data["Done"]==0)

{

return false;

}

}
return true;
I
Ivan van Oosterhout author 11/14/2012

This was it Christian,
I understand whats went wrong now.
Thank you very much for your expertise!
Regards Ivan

I
Ivan van Oosterhout author 11/15/2012

Hi Christian,
Maybe i can ask you a question about this?
And when there is no result? so no rows in my header?
Kind Regards,

C
cgphp 11/15/2012
global $dal;

$tblOrder = $dal->Table("header");

$rs = $tblOrder->Query("PlanID=".$oldvalues["aanmeldnum"],"");
if(db_numrows($rs) == 0) { return false; }
while($data = db_fetch_array($rs))

{

if($data["Done"]==0)

{

return false;

}

}
return true;