I want test field food_price value with value from query but cannot get the value.
this is my code, why when i run column food price empty ? please help me.
// Row Rendered event
function Row_Rendered()
{
$this->status->CurrentValue = "1";
// Get a field value
// NOTE: Modify your SQL here, replace the table name, field name and the condition
$fp = ExecuteScalar("SELECT food_price FROM food WHERE food_id = 2");
echo $fp;
$this->food_price->CurrentValue=$fp;
}
In PHPMaker, to display a value in the view page (or in a list/detail view), you should use the ViewValue property instead of CurrentValue. The CurrentValue is typically used for operations like insertions or updates to the database, whereas ViewValue is used for rendering the value on the page.Let’s modify your code accordingly:
// Row Rendered event
function Row_Rendered()
{
// Set a default value for status
$this->status->CurrentValue = "1";
// Execute the query to get the food price
$query = "SELECT food_price FROM food WHERE food_id = 2";
$fp = ExecuteScalar($query);
// Check if the query returned a value
if ($fp !== FALSE) {
// Use ViewValue for displaying the value
$this->food_price->ViewValue = $fp;
} else {
// Handle error or the absence of data
$this->food_price->ViewValue = "Error or no data";
}
}
In this updated code:The food price fetched from the database is assigned to ViewValue of the food_price field.If there’s an error in fetching the data or if no data is found, an appropriate message is set to the ViewValue.This should display the fetched food_price in the view context of your PHPMaker project. Remember to ensure that this code is placed in the correct event handler that corresponds to the context where you want to display this value. For a list page or a view page, Row_Rendered is typically the right event.
How to get the value food price with Parameter food id. i mean if i entry food id with value 2 or value 3 and the query return value food price with parameter food id.
when i try it nothing happen? with return value “Error or No Data” please help me.
// Row Rendered event
function Row_Rendered()
{
// Set a default value for status
$this->status->CurrentValue = "1";
$vid= $this->food_id->CurrentValue;
//$vid=2;
echo $vid;
// Execute the query to get the food price
$query = "SELECT food_price FROM food WHERE food_id = '".$vid."'";
$fp = ExecuteScalar($query);
// Check if the query returned a value
if ($fp !== FALSE) {
// Use ViewValue for displaying the value
$this->food_price->ViewValue = $fp;
} else {
// Handle error or the absence of data
$this->food_price->ViewValue = "Error or no data";
}
}
i want get the value food price from entry food id how to do it
if variable $vid = 2 with direct value no matter, but if i entry from column food id with 2 the sql not run when i debug $vid = this->food_id->CurrentValue is empty ? why is happen, any one help me please.can I filter sql and get the field food price from user entry?