Print PHP recordset to A4

php Portugal
  • 13 years ago
    Hi!
    I used some help to solve a little issue i've.

    I'm getting data from DB and then i display it in a grid with user details, like name, address, phone, etc...

    I can display to record at the time to be able to fit in a A4 page with Portrait layout.
    But i need to print this.. so i added a script to call print event.

    But if i've, like 200 users... i've to navigate by hand to all pages to print the pages...

    So.. what i would like to know if is there any solution to display all records but with some format that could fit to records by A4 sheet.

    Thanks in advance...
    MagNastiK














  • 13 years ago

    <STYLE TYPE="text/css">
    table { page-break-after: always }
    </STYLE>
    <?
     mysql_connect("localhost","","");
     mysql_select_db("mydb");
     $rs = mysql_query("select * from book limit 0,120;");
     gethtml($rs);
     mysql_free_result($rs);
     mysql_close();
    ?>
    <A HREF="BLOCKED SCRIPTwindow.print();"> Print </A>











    <?
       function gethtml($rs)
        {
     $i=1;
      while ($cols = mysql_fetch_array($rs)){
          if($i==1){
         echo "<H2> EX104.php </H2><br>";
         echo "<H3> Book Report  </H3><br>";
         echo "<table border='1' ";
         echo "<tr>";
            echo "<td align ='center' bgcolor='#fff000'>id</td> ";
         echo "<td align ='center' bgcolor='#fff000'>barcode </td> ";
           echo "<td  align ='center'  bgcolor='#fff000'>Book name </td> ";
          echo "<td align ='center'  bgcolor='#fff000'>author </td> ";
           echo "<td align ='center'  bgcolor='#fff000'>page no</td> ";
           echo "<td align ='center'  bgcolor='#fff000'>type </td> ";
           echo "<td align ='center'  bgcolor='#fff000'>year </td> ";
            echo "</tr>";
    } // end if
    $b++;   // กำหนดให้ line มันขึ้นแบบต่อเนื่องได้
      echo "<tr>";
      echo "<td>$b </td> ";
      echo "<td>$cols[0] </td> ";
      echo "<td>$cols[1] </td> ";
      echo "<td>$cols[2] </td> ";
      echo "<td>$cols[3] </td> ";
      echo "<td>$cols[4] </td> ";
      echo "<td>$cols[5] </td> ";
       echo "</tr>";
       $i++;
         if($i ==30){
         echo "</table>";
      $i=1;
       } //end if

































      } // end while
        } //end function
    ?>

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Better train people and risk they leave – than do nothing and risk they stay.” - Anonymous