This topic is locked
[SOLVED]

 Php Snipped Converted To "view As Custom"

6/26/2013 9:41:40 AM
PHPRunner General questions
C
copper21 author

Good morning,
I have a PHP Snippet that works using ECHO statement, but I am looking to "Convert" it to be able to put it into "View As Custom" on a field on the print page. I know that I must use "$value =" and can't use ECHO in "View As Custom", but am not sure how to put it into "View As Custom". Below listed is the PHP Snippet that I have:
global $conn;

$strSQLSelect = "SELECT * FROM training_recertifications WHERE (ps = '".$_SESSION["ps"]."') ORDER BY datetime_effective";

$rsSelect = db_query($strSQLSelect,$conn);
echo "<table border =1>";

echo "<th><P align=center><span style=padding-left:10px> Title:<span style=padding-right:10px></th>";

echo "<th><P align=center><span style=padding-left:10px> Hours: <span style=padding-right:10px></th>";

echo "<th><P align=center><span style=padding-left:10px> Date Effective: <span style=padding-right:10px></th>";

echo "<th><P align=center><span style=padding-left:10px> Expiration Date: <span style=padding-right:10px></th>";

echo "<th><P align=center><span style=padding-left:10px> PS #: <span style=padding-right:10px></th>";

echo "<th><P align=center><span style=padding-left:10px> Rank/Name: <span style=padding-right:10px></th>";

echo "<th><P align=center><span style=padding-left:10px> Work Location: <span style=padding-right:10px></th>";

echo "<th><P align=center><span style=padding-left:10px> Issued By: <span style=padding-right:10px></th>";
while($data1=db_fetch_array($rsSelect))

{

$effectivedate = $data1['datetime_effective'];
$effectivedate1 = date("m/d/Y",strtotime($effectivedate));
$expirationdate = $data1['datetime_expiring'];
$expirationdate1 = date("m/d/Y",strtotime($expirationdate));
echo "<tr>";

echo "<td><P align=left><span style=padding-left:10px>".$data1['title']."<span style=padding-right:10px></td>";

echo "<td><P align=center>".$data1['hours']."</td>";

echo "<td><P align=center>$effectivedate1</td>";

echo "<td><P align=center>$expirationdate1</td>";

echo "<td><P align=center>".$data1['ps']."</td>";

echo "<td><P align=left><span style=padding-left:10px>".$data1['rankname']."<span style=padding-right:10px></td>";

echo "<td><P align=center>".$data1['work_location']."</td>";

echo "<td><P align=left><span style=padding-left:10px>".$data1['issued_by']."<span style=padding-right:10px></td>";

echo "</tr>";
}
echo "</table>";
Thank you in advance for your help,
Brian

C
cgphp 6/26/2013

It's not a good practice fetch data with a query on "View as custom" field of a list page, you should review your main query on the "SQL editor" to join the training_recertifications table. Anyway, check this code:

global $conn;

$strSQLSelect = "SELECT * FROM training_recertifications WHERE (ps = '".$_SESSION["ps"]."') ORDER BY datetime_effective";

$rsSelect = db_query($strSQLSelect,$conn);
$html = "<table border =1>";

$html .= "<th><P align=center><span style=padding-left:10px> Title:<span style=padding-right:10px></th>";

$html .= "<th><P align=center><span style=padding-left:10px> Hours: <span style=padding-right:10px></th>";

$html .= "<th><P align=center><span style=padding-left:10px> Date Effective: <span style=padding-right:10px></th>";

$html .= "<th><P align=center><span style=padding-left:10px> Expiration Date: <span style=padding-right:10px></th>";

$html .= "<th><P align=center><span style=padding-left:10px> PS #: <span style=padding-right:10px></th>";

$html .= "<th><P align=center><span style=padding-left:10px> Rank/Name: <span style=padding-right:10px></th>";

$html .= "<th><P align=center><span style=padding-left:10px> Work Location: <span style=padding-right:10px></th>";

$html .= "<th><P align=center><span style=padding-left:10px> Issued By: <span style=padding-right:10px></th>";
while($data1 = db_fetch_array($rsSelect))

{

$effectivedate = $data1['datetime_effective'];
$effectivedate1 = date("m/d/Y",strtotime($effectivedate));
$expirationdate = $data1['datetime_expiring'];
$expirationdate1 = date("m/d/Y",strtotime($expirationdate));
$html .= "<tr>";

$html .= "<td><P align=left><span style=padding-left:10px>".$data1['title']."<span style=padding-right:10px></td>";

$html .= "<td><P align=center>".$data1['hours']."</td>";

$html .= "<td><P align=center>$effectivedate1</td>";

$html .= "<td><P align=center>$expirationdate1</td>";

$html .= "<td><P align=center>".$data1['ps']."</td>";

$html .= "<td><P align=left><span style=padding-left:10px>".$data1['rankname']."<span style=padding-right:10px></td>";

$html .= "<td><P align=center>".$data1['work_location']."</td>";

$html .= "<td><P align=left><span style=padding-left:10px>".$data1['issued_by']."<span style=padding-right:10px></td>";

$html .= "</tr>";

}
$html .= "</table>";

$value = $html;
C
copper21 author 6/26/2013

Thank you Cristian for your help on this. What I am trying to accomplish with this is listing child records on a print page. The master record is shown (data coming from a stock print page) and then this code shows the child records below it.
Brian