master/detail add page (v2018)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
hemin
User
Posts: 165

master/detail add page (v2018)

Post by hemin »

i am not sure but dose phpmaker support 3rd or 4th form of normalization?

for instance i have these tables: survey,surveryquestions,questisons.

survery: SID,Name, Date

surveryquestions: SQID,SID,QID,Answer1,Answer2

questions:QID,Question

is it possible for the master/detail survey/surveyquestion to grab the list of the questions as text for example ets say we have 12 questions, so the master/detail add page would be 1 to 12 row and get all the questions?


arbei
User
Posts: 9396

Post by arbei »

Setup the Edit Tag of the field "QID" in table "surveryquestions" with using lookup table "questions" and use "Question" as the display field.

So in Master/Detail of "survery" and "surveryquestion", the QID will show the question in text instead of the ID.

Read help file topic: "Project Setup" -> "Lookup Table" for more information.


kirondedshem
User
Posts: 642

Post by kirondedshem »

GIven tables as follows table(1)product:id,name table(2)sale:id,date table(3)sale_detail:id,sale_id,product_id
I've done something similar were i had tables, and even though i had setup master/detail as sale/sale_detail with product_id using lookup table to display product_name instaed of id. Say if i have 20 products.Client wanted the master/detail of sale/sale_detail add page to have default of 20 grid add rows, a row for each product with the product already selected into the product_id text field of the sale_detail add row. This is how i did it.

NOTE: I'll use your tables instead
survery: SID,Name, Date
surveryquestions: SQID,SID,QID,Answer1,Answer2
questions:QID,Question

  1. setup master/detail relationship between survery/surveryquestions with SID as link, enable master and detail add option
  2. setup QID in surveryquestions to use lookup table into questions value_field=QID and display field = Question, make it text/select
  3. during master/detail add setup the gridAddrowcount of the detail table to draw the exact number of orws equal to number of question.
    Go to page load event of the survey questions list page and paste
    function Page_Load() {
    	//set count to number of products
    	$this->GridAddRowCount = ew_ExecuteScalar("select count(*) from questions");
    }
  4. For each row in survey_questions set the a question as default selected for the QID. if lookup settings are correct each row shoud display the actual quaestion instead of the id
    got to Row_Rendering() event of the survey_questions and paste.
    function Row_Rendering() {
    	// Enter your code here
    	
    	if($this->PageID == "grid")
    		{
    		$grid_count = $this->GridAddRowCount;
    		$grid_num = $this->GridCnt;
    		if(isset($this->RowIndex))
    		{
    		$grid_num = $this->RowIndex;
    		//only when we are dawing actual rows
    		if(($grid_count >= $grid_num) && is_int($grid_num) && ($grid_num >= 1))
    		{
    			$offseter = $grid_num - 1;
    			//get & set product details
    			$product = ew_ExecuteRow("SELECT QID FROM questions limit 1 OFFSET $offseter");
    			$this->QID->CurrentValue = $product["QID"];
    
    			//hide grid delete
    			$this->ListOptions->Items["griddelete"]->Visible = FALSE;
    			
    			
    		}
    		
    		
    		}
      }
    
    }

NOTE: you might want to set custom attributes of QID and add "readonly=true" to disable editing


hemin
User
Posts: 165

Post by hemin »

Thanks a ton kirondedshem , that is exactly what i wanted.


ichanz
User
Posts: 21
Location: Jakarta - Indonesia

Post by ichanz »

Nice post, but somehow this post does not worked for phpmaker 2018.
If there any update?


kirondedshem
User
Posts: 642

Post by kirondedshem »

It should as I am only using row_rendering and page_load.
Just lookout for this line $this->QID->CurrentValue = $product["QID"];

To ensure its set correctly you can even var_dump your data to ensure you are still settings the right data.


ichanz
User
Posts: 21
Location: Jakarta - Indonesia

Post by ichanz »

I don't know what went wrong, i did run var_dump (also put on debug mode) no error come up, but still does not work on v2018.
the same code I pasted to v2017 and it's well....


mobhar
User
Posts: 11741

Post by mobhar »

When you tried to var_dump the variable, what did you see on the screen? Did you see the result/output of the variable? Also, post your code for more discussion.


kirondedshem
User
Posts: 642

Post by kirondedshem »

but still does not work on v2018. the same code I pasted to v2017 and it's well
Since you are aboe to make it work in 2017, you obviously have something set differently in version 2018, maybe the field settings, maybe how you run your query etc.

SO also indicate what you mean by its not working in 2018, what exactly is not working, are your target fields not autofilled, are your queries not picking the right value for each fields, is the filled value ID not looking up and displaying the right text in the forms. And when you vardump in row_rendering are you sure each query is picking the right value to be assigned for each row etc etc

Post your code here but you should be able to idenditfy what part of the code the not working so we can start from there


ichanz
User
Posts: 21
Location: Jakarta - Indonesia

Post by ichanz »

  1. Table: Biodata Field: id_biodata(INT), Name(VARCHAR), POB(VARCHAR), DOB(DATE), Gender(INT); ( this is the master table )
  2. Table: inview field: id_inview(INT), fk_biodata, question (INT), answer(INT); ( this is the detail table)
  3. Table: inques field: id_inque(INT)s, questn(VARCHAR), shows(INT); (this is the question source)

I already set field: question(INT) on inview table, lookup to table inques link field to id_inques(INT) with display #1 questn(VARCHAR)

at the inview: Table specific, List Page, page_load :

function Page_Load() {
$this->GridAddRowCount = ew_ExecuteScalar("select count(*) from inques where shows!= '0'");
var_dump($this->GridAddRowCount);
}  

at the inview: table specific, Row_Rendering :

function Row_Rendering() {
	if($this->PageID == "grid"){
	$grid_count = $this->GridAddRowCount;
	$grid_num = $this->GridCnt;
		if(isset($this->RowIndex)){
		$grid_num = $this->RowIndex;
		//only when we are dawing actual rows
			if(($grid_count >= $grid_num) && is_int($grid_num) && ($grid_num >= 1)){
			$offseter = $grid_num - 1;
			//get & set question details
			$quest = ew_ExecuteRow("SELECT questn FROM inques WHERE shows != 0 limit 1 OFFSET $offseter");
			$this->question->CurrentValue = $quest["question"];
			//hide grid delete
			$this->ListOptions->Items["griddelete"]->Visible = FALSE;
			}
		}	
	}
}

After regenerating the code,
var_dump:
string(1) "2" ==> which is correct
but on detail table inview field question only shows 0
( there are a 2 row showing but question does not appear);

Thanks.


kirondedshem
User
Posts: 642

Post by kirondedshem »

$this->question->CurrentValue = $quest["question"];

First of all This should be generating a php errors for the above lines of code (enable php errors in ini file if they are disabled) coz the result from ew_ExecuteRow does not contain a field called "question"

$quest = ew_ExecuteRow("SELECT questn FROM inques WHERE shows != 0 limit 1 OFFSET $offseter");
I already set field: question(INT) on inview table, lookup to table inques link field to id_inques(INT) with display #1 questn(VARCHAR)

YOu are supposed to query for the foreign key value ie "id_inque" NOT "questn", the filed "question" is of type INT so you cant assign it a varchar from questn, the lookup settings will query and show the questn text for you, so try chnaging above lines to

$quest = ew_ExecuteRow("SELECT id_inque FROM inques WHERE shows != 0 limit 1 OFFSET $offseter");
$this->question->CurrentValue = $quest["id_inque"];


ichanz
User
Posts: 21
Location: Jakarta - Indonesia

Post by ichanz »

I just made exactly the same tables and field names as yours,
follow along step by step as instructed to,
copied and pasted the code to the place.

After Generating the code, still does not work on 2018.
but, works well on 2017.

Still have no idea, why...


kirondedshem
User
Posts: 642

Post by kirondedshem »

OK Ive recreated your database structure and did a live test on my machine,here is the sql for what i used (I left out foreign key constraints on purpose)

CREATE TABLE Biodata(
id_biodata int(11) AUTO_INCREMENT PRIMARY KEY,
Name varchar(50),
POB varchar(50),
DOB date,
Gender int(11)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE inques(
id_inque int(11) AUTO_INCREMENT PRIMARY KEY,
questn varchar(50),
shows int(11)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE inview(
id_inview int(11) AUTO_INCREMENT PRIMARY KEY,
fk_biodata int(11),
question int(11),
answer int(11)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

So the code still works except
NOTE:If used in master detail add form

the PageId is not "grid" It "gridcls", So correct the line below

if($this->PageID == "gridcls")

and still the query and assignment of value to CurrentValue is wrong so still use one below

//get & set question details
	$quest = ew_ExecuteRow("SELECT id_inque FROM inques WHERE shows != 0 limit 1 OFFSET $offseter");
	$this->question->CurrentValue = $quest["id_inque"];

Here is the full event code that ive used

// Row Rendering event
	function Row_Rendering() {

		// Enter your code here
		var_dump($this->PageID);
		if($this->PageID == "gridcls"){
	$grid_count = $this->GridAddRowCount;
	$grid_num = $this->GridCnt;
	if(isset($this->RowIndex)){
	$grid_num = $this->RowIndex;

	//only when we are dawing actual rows
	if(($grid_count >= $grid_num) && is_int($grid_num) && ($grid_num >= 1)){
	$offseter = $grid_num - 1;

	//get & set question details
	$quest = ew_ExecuteRow("SELECT id_inque FROM inques WHERE shows != 0 limit 1 OFFSET $offseter");
	$this->question->CurrentValue = $quest["id_inque"];

	//hide grid delete
	$this->ListOptions->Items["griddelete"]->Visible = FALSE;
	}
	}
	}
	}

HINT:ALways check code line by line, what values you are conditioning on incase you have ifstatements, thats the only way t know what you need to change or where code is not reaching


ichanz
User
Posts: 21
Location: Jakarta - Indonesia

Post by ichanz »

Solved, Thank you very much....


estiga
User
Posts: 1

Post by estiga »

very nice post, but in v2019, $GridCnt is not recognized, it might be replaced with $RowCnt, you can check it with var_dump ($this);


Post Reply