This topic is locked
[SOLVED]

 Having trouble getting primary key value

4/21/2010 7:10:28 AM
PHPRunner General questions
F
frocco author

Hello,
//Occurs before list page is displayed

global $strTableName;

$link = "<a href='invoice.php?id='" . $strTableName."_masterkey1" . ">Print Invoice</a>";

$xt->assign("link1", $link);
Hello,

The pkey value is blank.

What am I doing wrong?
Thanks
Frank

Sergey Kornilov admin 4/21/2010

This code doesn't make much sense.
What page you trying to apply this code to?

F
frocco author 4/21/2010



This code doesn't make much sense.
What page you trying to apply this code to?


I am on the list page and trying to add a link to print an invoice.

All I get is the string value name of the table, no pkey.
Thanks

B
battyone 4/21/2010

Couldn't you use $values["keyFieldName"]?

Sergey Kornilov admin 4/21/2010

List page displays a set of records. Each record has it's own primary key.
Which of those records you trying to refer to in BeforeDisplay event? You need to provide a better description of what you trying to achieve.

B
battyone 4/21/2010



List page displays a set of records. Each record has it's own primary key.
Which of those records you trying to refer to in BeforeDisplay event? You need to provide a better description of what you trying to achieve.


I think he wants to add a button to quickly print/view the form using the key for that row. That is how I am reading it.

F
frocco author 4/21/2010

>>I think he wants to add a button to quickly print/view the form using the key for that row. That is how I am reading it. <<
Yes, that is it.
Thanks

B
battyone 4/21/2010



>>I think he wants to add a button to quickly print/view the form using the key for that row. That is how I am reading it. <<
Yes, that is it.
Thanks


I've not yet dived deeply into PHPRunner and how it generates things but I see something like this (For Agent names in one of my tables)


{BEGIN agent_fieldcolumn}<TD class=borderbody vAlign=middle {$agent_style}>{$agent_value} </TD>{END agent_fieldcolumn}


I believe $agent_value holds for that specific row the entry for the database. You may be able to add a column that displays id then modify that column to instead of being displayed text instead be the link you need. Something like


{BEGIN agent_fieldcolumn}<TD class = borderbody vAllign=middle {$agent_Style}> <a href=foo.php?id={$agent_value}>Click to print</a></TD> {END agent_fieldcolumn}


Please be advised that I am more of saying that $FOO_value may hold the field you need, and since I am quite craptacular at coding I can't promise that it will work in any regard.

Sergey Kornilov admin 4/21/2010

I just don't get it.
Frank, I recommend to post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL along with screenshot of further explanation where this link or links should appear and what would be the sample URL.

F
frocco author 4/21/2010



I just don't get it.
Frank, I recommend to post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL along with screenshot of further explanation where this link or links should appear and what would be the sample URL.


Ok, I am at work now and will post later.
I am in the list event before row is displayed and just need to get the Id field in my Mysql database table or row and append it to a link that calls an invoice.php file I wrote.
I post later.

F
frocco author 4/21/2010

I created the demo account.
Thanks

F
frocco author 4/22/2010

As support suggested, moved code to Occurs after record is processed in List events.



$record["link1"] = "<a href='invoice.php?id=" . $data["Id"]."'" . " target='_blank'>Print Department Invoice</a>";
T
taumic 4/26/2010

Hello Frank,
can you send the whole solution here ( in small steps) ?

I am verry interesting on it!
Thank you
Mike

E
electromotive 5/5/2010

If I understand what you are asking for correctly, last year I did something similar, where I had an external print_invoice.php which needed the data passed to it.
How I did it, was create a PHPR view with the data I needed for the invoice (invoice_print or whatever). I linked the invoice table to the invoice_print (the normal way in tables tab, no preview needed). Then in the events tab, invoice_print list_page : after record processed event, I loaded up the data into session variables and then called the external print_invoice.php. The print_invoice.php had to first connect to the session, and then gained access to the session_variables. In my case I didn't want the the print_invoice.php to open and access the database directly so it remained independent of the database and structure, I preferred to pass the data instead. That's your choice. To make it robust you'll need to pass something, if not the data itself then the database/table name and access parameters.
// invoice_print list: after record processed event

if ($data["Invoice number"]) { //option to verify that there is actual data to print

$_SESSION["invoice_number"]=$data["Invoice number"];

...

// assign remainder of session variables

...

?>

<script>

window.location='external_php/print_invoice.php'; //whatever your path is.

</script>

<?php

exit();

}
This event diverts list to the external php, so you never actually see the PHPR generated list, so it doesn't matter how its formatted, just that the list has the fields you need. Turn off add/edit/delete/view/print etc.
The goal of this approach was to ceate a normal detail link beside each list item which prints the particular invoice (as opposed to using the check boxes and adding custom buttons) This way the whole thing keeps working even if the page is reset or changed. There is obviously several ways to do this.
My external print_invoice.php generates a PDF (on the server) which gets displayed, and if the data is acceptable, then the user hits the print button which prints the invoice on their local or network printer. Works on any server/client platform combinations.
In print_invoice.php, it first contains a session_start() statement.

Then checks that the session variables are there and builds the report.

session_start();

if (isset($_SESSION['invoice_number'])) {

...

$pdf->Output();

}
The report writer php could print several different types of reports, invoices, statements, etc, just pass a type parameter. Alternatively you can have a separate php for each type of report.
My printouts/labels are quite complex with vertical text, barcodes, different fonts and sizes, etc., but all easily handled by pdf.