This topic is locked

multiple return false?

7/7/2009 5:22:07 PM
PHPRunner General questions
U
Urnso author

I am using this code to try and stop users from completing jobs that have tasks still open in another table. Edit page:Before record updated.

global $conn,$strTableName,$data,$cntcomp;

$sql = "select *, COUNT(JobNo) from subrequests where JobNo='".$_SESSION[$strTableName."_masterkey1"]."' AND CompletedDate IS NULL GROUP BY JobNo";

$rs = db_query($sql,$conn);

$data = db_fetch_array($rs);

$cntcomp = $data["COUNT(JobNo)"];
If ($values["Completed"] && $cntcomp > 0) {

Echo "<font color=red><strong>Open tasks need to be closed before completing jobs.</strong></font>";

return false;

}
If (!$values["InQueue"] && $values["AssignedTo"] == ""){

Echo "<font color=red><strong>Job Requires a Lead to be taken out of Queue.</strong></font>";

return false;

}


The record I am using does have open subrequests and the sql query works fine in phpmyadmin. I think I'm missing something in the php portion of this.
1st question: I have multiple "return false" is that going to work?

2nd: If the user checks the Completed box and hits save it should check subrequests for empty CompletedDates. If it finds empty it should count those and make $cntcomp greater than 0.... Thus giving the error msg.
I don't get any error msg's but it just doesn't work either. Hope someone can help me. Thx!

J
Jane 7/8/2009

Hi,
your code looks good.

I recommend you to publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

U
Urnso author 7/9/2009

I'm sorry I forgot to mention that the table I was comparing to was not the mastertable. Requests is the Master and subrequests is the child. So I used the $key value from requests instead of $_SESSION[$strTableName."_masterkey1"] which was not working. The below code allowed me to stop action happening on the edit page based on field values in another table. Thought this might help some others.

global $conn,$strTableName,$opensubs,$keys;

$sql = "select * from subrequests where JobNo='".$keys["JobNo"]."' AND CompletedDate IS NULL";

$rs = db_query($sql,$conn);

$opensubs = mysql_num_rows($rs);

//don't allow the user to close the record if subs are still open.

If ($opensubs > 0) {

echo "<font color=red><strong>".$opensubs." Subrequest(s) are still open for this job.<br>";

echo "You can't close this Job Request until all tasks are completed</font></strong>";

$xt->assign("Completed_fieldblock",false);

}