This topic is locked

List page database value

9/10/2018 8:36:11 AM
PHPRunner General questions
G
georgweber author

PHPrunner 9,8
I mad this code for access a total of a field in the database on the list page of each record
global $pageObject;

$record = $pageObject->getCurrentRecord();

$strSQLExists = "SELECT sum(Quantidade) AS totalcomprado FROM horas_voo_comprados where matricula = '".$record["Matricula"]."'";

$rsExists = db_query($strSQLExists);

$data=db_fetch_array($rsExists);

if($data){

echo "<BR>Total Horas comprados: ";

echo $data["totalcomprado"];

}
I don´t get the result. It´s show only "Total Horas comprados:"
???????

admin 9/10/2018

You need to perform a basic tropubleshooting steps. Instead of executing your SQL query print it on the page and run that SQL manually against your database to see what kind of data it returns.

G
georgweber author 9/10/2018



You need to perform a basic tropubleshooting steps. Instead of executing your SQL query print it on the page and run that SQL manually against your database to see what kind of data it returns.


Thank you for reply
The problem is only this
.$record["Matricula"]
If i give a value manualy so it´s works fine. But i need that the code read the actual value of each record

admin 9/10/2018

Maybe you adding this code to wrong place and $record = $pageObject->getCurrentRecord(); doesn't return any data. Every event comes with a description of how to access underlying record data. Make sure that you using the method offered in that specific event description.

fhumanes 9/10/2018

Hi,
The getCurrentRecord() method is only available in View and Edit (according to manual).
To do the calculation you can include the code in the BeforeProcessRowList event ($data, $pageObject) and there you have the $data array with the values of the fields in the record.
Regards,