Buscar: Ok
        
Inicio > Ejemplos de uso
PHP & MySQL
This example shows how to prepare a report using PHP & MySQL.

Developed by Ing. Adalberto Ordoñez J. Bolivia.
Email: adalberto@caoba.entelnet.bo
URL: http://www.abel-bo.com

Minimum requeriments:
Windows 98 SE; Apache 1.3.23 (win32); php 4.1.1; MySQL 3.23.47 running on localhost
Also working for Linux, Aix, Solaris, NT SERVER 2000.

You must create the MySQL database: http://localhost/phpmyadmin/
Database name: Test
Table name: dbabel

The following are the fields from the table:
Code Name Phone Address
222 Peter Thompson 123-456789 Brown 556
111 Adalberto Ordoñez J. 591-2-7061856 Florida 1334
333 Donal Waide 4555-8897 Mozart 11

The code will create a report file (data.rpv), then the same code will display the report by processing the file data.rpv (see the last line of the code).
Descargar archivos del ejemplo (9Kb)
Código
<?php
  function conectarse()
  {
      if(!($link=mysql_connect("localhost","root","")))
      {
          echo "Error when connecting to Database";
          exit;
      }
      if(!mysql_select_db("test",$link))
      {
          echo "Error when selecting Database";
          exit;
      }
      return $link;
  }
?>
<html>
<head>
       <title>QUERY TO  DB</title>
</head>
<body>
<h3>Example using Rpv and php</h3>
<?php

$fp = fopen("C:\Program Files\Rpv\reports\data.rpv", "w");
fwrite ($fp, "REPORT_TITLE=Report generated from php
$col_0=500
$col_1=2000
$col_2=4500
$col_3=7000
tm=350
pagelength=15000
pagewidth=11907
spacing=220
[HEADER]
{f=arial;s=14;a=c;\n}
{5500;b=y;c=2}DEVELOPERS REPORT {\n;\n;\n;b=n;c=0;s=8}
{xyline=500,700,10000,700}
{$col_0;b=y} CODE {$col_1} NAME {$col_2} PHONE {$col_3} ADDRESS {s=7;4000} {\n;b=n;s=8}
{xyline=500,1100,10000,1100} {\n}
[DATA]
");
 $link=conectarse();
 $resultado=mysql_query("select * from dbabel order by code", $link);
while($row=mysql_fetch_array($result))
 {
    echo " Ok.   ";
   fwrite ($fp, "{$col_0} $row[code] {$col_1} $row[name] {$col_2} $row[phone] {$col_3} $row[address] {\n}
   ");
 }
fclose($fp);
 mysql_free_result($result);
 mysql_close($link);
 ?>
 </table>
 </body>
 </html>
<?php
exec('C:\Progra~1\Rpv\Rpv.exe C:\Progra~1\Rpv\reports\data.rpv');
?>
Reporte RPV
REPORT_TITLE=Report generated from php
$col_0=750
$col_1=2500
$col_2=4500
$col_3=7000
tm=350
pagelength=15000
pagewidth=11907
spacing=220
[HEADER]
{f=arial;s=14;a=c;\n}
{5500;b=y;c=2}DEVELOPERS REPORT {\n;\n;\n;b=n;c=0;s=8}
{xyline=500,700,10000,700}
{$col_0;b=y} CODE {$col_1} NAME {$col_2} PHONE {$col_3} ADDRESS {s=7;4000} {\n;b=n;s=8}
{xyline=500,1100,10000,1100} {\n}
[DATA]
{$col_0} 222{$col_1} Peter Thompson {$col_2} 123-456789{$col_3} Brown 556 {\n}
{$col_0} 111{$col_1} Adalberto Ordoñez J.{$col_2} 591-2-7061856{$col_3} Florida 1334 {\n}
{$col_0} 333{$col_1} Donal Waide {$col_2} 4555-8897{$col_3} Mozart 11 {\n}
Imágen
Screenshot