Get value from another table

I have a master detail table.
in the detail table I want to retrieve all the value tables from “tquoestion” (id_question, question).
but the value that appears is the bottom record. can anyone provide a solution so that my detail table can fill in questions from the tquestion table.
this is my code

function ListOptions_Rendering()
{

$val = ExecuteScalar("SELECT COUNT(*) FROM tquestion");
$this->GridAddRowCount = $val;

$resultSet = ExecuteQuery("SELECT question FROM tquestion");
while ($row = $resultSet->fetchAssociative()) {
$value = $row["question"];
$this->Q1->EditValue = $value;
}
}


I have tried the following code too, but the results displayed are all the same (the bottom query result)

$sql1 = "SELECT question FROM tquestion";
$stmt1 = ExecuteQuery($sql1);
$value = "";
if ($stmt1->rowCount() > 0) {
while ($row = $stmt1->fetchAssociative()) {
$value = $row["question"];
$this->Q1->EditValue = $value;
}
echo "Result: <br>" . $value;
} else {
echo "No records are found.";
}

You should set the EditValue of the field for each row in Row_Rendered server event.

I have moved the code to Row_Rendered as per the instructions, and this code is in the detail table.
the result is still the same as before

You cannot put everything in Row_Rendered, which is only for setting EditValue of that row only.

do you mean like this?

function Row_Rendered()
{
$this->Q1->EditValue = $value;
}


is there any solution and help me

can you give me an example

You may want to think why your $value is undefined and how to handle it.

Hint: Variable scope


the result is still the same if I create a variable in global, can anyone help?

You cannot use Row_Rendered server event for such case.

Since you want to implement it for Grid-Add mode, then you should put this following PHP code inside the Startup Script section of List Page of your tquestion table:

	<?php
	if (CurrentPage()->CurrentAction == "gridadd") {
		$result = ExecuteQuery("SELECT question FROM tquestion");
		$i = 1;
		while ($row = $result->fetchAssociative()) {
			$value = $row["question"];
			?>
			$("#x<?php echo $i; ?>_question").val("<?php echo $value; ?>");
			<?php
			$i++;
		}
	}
	?>

A bit tricky, but it works

Actually you already have the answer yourself, try to put them together.

Hints:

  • ListOptions_Rendering
  • Row_Rendered
  • Variable Scope