#native_company# #native_desc#

Put values to HTML object from PHP variables

By Hugo A. Contreras Barrios
on December 14, 2000

Maybe this is a simple tip, but I lost many hours to find it.

I wanted to list the content of Postgres’ table and show some calculate at top
of the list without recalculate.

My solution is:

1) Put INPUT boxes before the table for data

2) Get, calculate and listen data

3) Assign PHP var to INPUT boxes

        /* 1. Define a INPUT boxes to show calculate */
      <TD> Total de Reportes: $rt <INPUT TYPE="text" NAME="RT" SIZE=3></TD>
      <TD> Cerrados: <INPUT TYPE="text" NAME="RC" SIZE=3></TD>
      <TD> Abiertos: <INPUT TYPE="text" NAME="RA" SIZE=3></TD>

        /* 2.1 Get data from Postgres' table */

   $sql="SELECT oid,* FROM reportes ";
   if (($AUDITORIA) and ($AUDITORIA!="all")) {$sql.=" WHERE id_auditoria='$AUDITORIA' ";}
   $sql.=" ORDER BY id_auditoria,id_rnc;";

        /* List and Calcule */
       echo "

Don't have reports </H>

"; else: echo "<TABLE BORDER=1> <TH>Audit</TH><TH>No. Report</TH><TH>Area</TH> <TH>Emision</TH><TH>Closed</TH>"; $ra=$rc=0; /* Put counter to 0 */ for($j=0;$j<$rows;$j++): $id = pg_result($result_set,$j,"oid"); $cierre = pg_result($result_set,$j,"f_cierre"); if ($cierre): $rc++; else: $ra++; endif; /* Calcule */ $v_auditoria = pg_result($result_set,$j,"id_auditoria"); echo "<TR><TD width=80><FONT size=2><a href=acp03.php?name=$id>". $v_auditoria. "</a></FONT></TD>"; echo "<TD width=200><FONT size=2>" . pg_result($result_set,$j,"id_rnc") . "</FONT></TD>"; echo "<TD width=60><FONT size=2>" . pg_result($result_set,$j,"area") . "</FONT></TD>"; echo "<TD><FONT size=2>" . pg_result($result_set,$j,"f_compromiso") . "</FONT></TD>"; echo "<TD align=center><FONT size=2>".$cierre."</FONT></TD></TR>"; endfor; echo "</TABLE>"; endif; $rt=$ra+$rc; ?> /* 3. Assign PHP variables to INPUT boxes */ <SCRIPT LANGUAJE="JAVASCRIPT"> <? echo "RT.value = $rt;"; echo "RA.value = $ra;"; echo "RC.value = $rc;"; ?> </SCRIPT>