This topic is locked
[SOLVED]

 read only before display

3/14/2012 2:27:09 PM
PHPRunner General questions
S
stiven author

Hello everyone,
I am trying to make a field read only on before display event but it is not working hope anyone can help me on this here is the code


global $conn;

global $readonlyfields;
$sql = "SELECT certificates,escorts,limousine,dove_release FROM contract WHERE `case_#` = '".$values["case_no"]."'";

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

$row = db_fetch_array($result);
if($row['certificates'] = '' || $row['certificates'] = '0'){
$readonlyfields["order_scort"] = '';
}
print_r ($row);// output im getting all the columns empty when i am 100% sure the certificates column has a value of 14
echo $row['certificates'] . " certificates <br/>";// output is blank no value on certificates column
echo $sql;//output is ok syntax is right
$readonlyfields["order_scort"] = '';// tried to set it manually but still is not showing as read only
print_r($readonlyfields);// displays all the fields that are rea only including "order_scort" in the array but it is still not showing as readonly on the page


Thanks for your help

C
cgphp 3/14/2012

You can use the "Javascript onload" event to make a field readonly. More info here: http://xlinesoft.com/phprunner/docs/makereadonly.htm

Sergey Kornilov admin 3/14/2012

BeforeDisplay event don't have access to $values array which means your SQL Query never returns any data.
You can use ProcessValues event to save $values array in Session variable and then use it in BeforeDisplay event.

More info: http://xlinesoft.com/phprunner/docs/process_record_values.htm

S
stiven author 3/14/2012

Yes i could use javascript onLoad event, but how am i going to get the value from the other table on javascript onload? i need to make it read only dependent on a value from another table



You can use the "Javascript onload" event to make a field readonly. More info here: http://xlinesoft.com/phprunner/docs/makereadonly.htm

S
stiven author 3/14/2012

I think it does have access to $values array because I am getting the value when i echo the sql query. maybe it doesn't have access to the db_functions.. i replace the db functions to this



$sql = "SELECT certificates,escorts,limousine,dove_release FROM contract WHERE `case_#` = ".$values["case_no"]."";

$result = mysql_query($sql,$conn);//i replaced this before it was db_query

$row = mysql_fetch_array($result);//i replace this before it was db_fetch_array
print_r($row);


this is the output
Array ( [0] => 14.00 [certificates] => [1] => [escorts] => [2] => [limousine] => [3] => [dove_release] => )
strange. the value 14.00 should be the [certificates] key but it isn't why is it adding a new key[0]?



BeforeDisplay event don't have access to $values array which means your SQL Query never returns any data.
You can use ProcessValues event to save $values array in Session variable and then use it in BeforeDisplay event.

More info: http://xlinesoft.com/phprunner/docs/process_record_values.htm

C
cgphp 3/14/2012

Does the case_# field is INT type? If so, the query should be:

global $conn;

global $readonlyfields;
$sql = "SELECT certificates,escorts,limousine,dove_release FROM contract WHERE `case_#` = ".$values["case_no"]; //no single quote if INT type

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

$row = db_fetch_array($result);
S
stiven author 3/14/2012

yes it is. I had already changed it to this


$sql = "SELECT certificates,escorts,limousine,dove_release FROM contract WHERE `case_#` = ".$values["case_no"]."";

$result = mysql_query($sql,$conn);//i replaced this before it was db_query

$row = mysql_fetch_array($result);//i replace this before it was db_fetch_array
print_r($row);


this is the output.
Array ( [0] => 14.00 [certificates] => [1] => [escorts] => [2] => [limousine] => [3] => [doverelease] => )
strange?. :/



Does the case
# field is INT type? If so, the query should be:

global $conn;

global $readonlyfields;
$sql = "SELECT certificates,escorts,limousine,dove_release FROM contract WHERE `case_#` = ".$values["case_no"]; //no single quote if INT type

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

$row = db_fetch_array($result);