This topic is locked

prepopulate table from an earlier visit

2/17/2009 5:21:35 PM
PHPRunner General questions
V
vytb author

How to prepopulate table from an earlier visit of the same person?
Mastertable 'visit' has

  1. its own mastertable 'subject' on visit.subjectid = subject.subjectid
  2. a childtable 'd' on visit.visitid = d.visitid
    How to pre-populate 'd.populate' from the table d of an earlier visit (this means with another d.visitid and the same visit.subjectid) ?

J
Jane 2/18/2009

Hi,
select this value from subject table, save it in the session variable and then use it as default value on the "Edit as" settings dialog.

V
vytb author 2/18/2009

Hi,

select this value from subject table, save it in the session variable and then use it as default value on the "Edit as" settings dialog.


There is no subjectid field in the table d (it's in the visit table which is the master for d), so how can I save it as default on the 'edit as'? Thus how the code should appear?

J
Jane 2/19/2009

Hi,
you can select subjectid from visit table based on the visitid value and then select correct field value from subject table based on the selected subjectid value.

V
vytb author 4/2/2009

Thanks Jane,
As you can see in the code below,

  • While prepopulating d.populate from the earlier d.populate from the earlier visit, where d.visitid=visit.id and visit.subjectid = subject.subjectid,
  • I use session masterkey d.visitid = visit.id to get visit.subjectid and so to select an earlier d.populate of the different visit but the same visit.subjectid = subject.subjectid
    This functions, however I get two problems:
  • The add page needs refresh, otherwise the earlier visit.subjectid is used
  • I get first earlier record; I need the last one (with max(visit.visitnb)).
    How can I achieve this?
    Here is the code

    [codebox]global $conn, $strTableName;
    $str = "select subjectid, id

    from visit where id=".$_SESSION[$strTableName."_masterkey1"];

    $rs = db_query($str,$conn);

    $data = db_fetch_array($rs);
    $str = "select subjectid, id

    from visit where subjectid=".$data["subjectid"];

    $rs = db_query($str,$conn);

    $data2 = db_fetch_array($rs);
    $str = "select d.populate

    from d where visitid=".$data2["id"];

    $rs = db_query($str,$conn);

    $data1 = db_fetch_array($rs);
    $_SESSION["populate"] = $data1["populate"];

    [/codebox]

J
Jane 4/3/2009

Hi,
to sort selected records add ORDER BY clause to your query:

$str = "select subjectid, id

from visit where id=".$_SESSION[$strTableName."_masterkey1"]." Order by fieldname desc";


Regarding the second question.

Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

V
vytb author 4/7/2009

Hi,

to sort selected records add ORDER BY clause to your query:
Regarding the second question.

Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.


Thank you, Jane.
However, sorting visit.id has no sense since it's only one. I would need to sort the second selection:

------------------------------------

$str = "select subjectid, id

from visit where subjectid=".$data["subjectid"];

-------------------------------------

however adding here

------------------------------------
." Order by id desc"
---------------------------------

does nothing. Where is my error?

J
Jane 4/8/2009

Hi,
It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

V
vytb author 8/25/2009



Hi,
It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and open a ticket at <a href="http://support.xlinesoft.com"; target="_blank">http://support.xlinesoft.com</a>; sending a URL to your pages along with instructions on reproducing this error.


For some unknown reason I could not upload all the tables successfully. However, I just sent the entire project directory to support@xlinesoft.com. Could you take a look please at the event code in pages loc (BeforeProcessAdd) and d (BeforeProcessAdd)?
The idea is following: every visit of every person has the same detail tables. I'm trying to prepopulate detail table from the last earlier visit of the same person. In order to do this, I'm grabbing the visit id from the present detail table and so the person id from the visit table. Then I can have all visit id's of the same person. Then, I would order them desc and prepopulate from the latest one which will be the first in line then, as you have proposed. However, if I apply desc for the second step (order visit id's desc), the code does not function at all (no error btw).
As the result I still have the earliest visit id and not the latest. What I am missing?
I'm tempted to use max() for the visit id, but where should I incorporate it?

J
Jane 8/26/2009

Hi,
just use this code:

$str = "select SubjectId, id from visit where SubjectId=".$data["SubjectId"]." order by id desc";
V
vytb author 8/26/2009

Thank you Jane,
Yes, I've tried it. For some strange reason then I receive an empty detail page - it is not prepopulated.

V
vytb author 9/1/2009

Following your recommendations (code), I don't have the detail table prepopulated at all. Where should I look for the problem? Maybe desc makes the table prepopulate from itself? Help please!

V
vytb author 10/7/2009

Hi again,
In order to clarify the problem, I've created a little app at demo.
There is one subject, three visits. Every visit has his number n. Every visit has a child table 'event' with a field 'a'. In the visit 1, a = 'from the first visit', In the visit 2, a = 'from the second visit'. In visit 3, there is no a yet. When adding 'event' for the third visit, I want a to be from the last visit (this time a must be 'from the second visit').
My code in the BeforeProcessAdd event is
--------------------------------------------------------------------------------------------

global $conn, $strTableName;
$str = "select subjectid

from visit where visitid=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$str = "select visitid, n

from visit where subjectid=".$data["subjectid"]." Order by n desc";

$rs = db_query($str,$conn);

$data1 = db_fetch_array($rs);
$str = "select a

from event where visitid=".$data1["visitid"];

$rs = db_query($str,$conn);

$data2 = db_fetch_array($rs);
$data2["a"] = $_SESSION["a"];

------------------------------------------------------------------------------------------

event.a by default is $_SESSION["a"]

------------------------------------------------------------------------------------------
However the field a is not prepopulated. Where is my error?

J
Jane 10/8/2009

Hi,
please see my changes below:

global $conn, $strTableName;
$str = "select subjectid

from visit where visitid=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$str = "select visit.visitid, n from visit inner join event on visit.visitid=event.visitid

where subjectid=".$data["subjectid"]." Order by n desc";

$rs = db_query($str,$conn);

$data1 = db_fetch_array($rs);
$str = "select a from event where visitid=".$data1["visitid"];

$rs = db_query($str,$conn);

$data2 = db_fetch_array($rs);



$_SESSION["a"] = $data2["a"];


Also I recommend you to contact support@xlinesoft.com directly with all questions about custom events.