Limit the number of forms to be printed per page

Asked

Viewed 109 times

1

I have the following code below that generates a form of information brought from the bank.

If I print 2 forms of this per page is right on an A4 sheet, but the question is that I have tried to modify the layout in various ways and is not getting good.

What’s going on is that when I ask him to print it in moments he puts 3 forms on the page and 3 is cut and mess up the rest.

It is possible to limit how many forms will be printed per page?

<?php
include"conexao.php";

function geraCodigoBarra($numero) {
    $fino = 1;
    $largo = 3;
    $altura = 30;

    $barcodes[0] = '00110';
    $barcodes[1] = '10001';
    $barcodes[2] = '01001';
    $barcodes[3] = '11000';
    $barcodes[4] = '00101';
    $barcodes[5] = '10100';
    $barcodes[6] = '01100';
    $barcodes[7] = '00011';
    $barcodes[8] = '10010';
    $barcodes[9] = '01010';

    for ($f1 = 9; $f1 >= 0; $f1--) {
        for ($f2 = 9; $f2 >= 0; $f2--) {
            $f = ($f1 * 10) + $f2;
            $texto = '';
            for ($i = 1; $i < 6; $i++) {
                $texto .= substr($barcodes[$f1], ($i - 1), 1) . substr($barcodes[$f2], ($i - 1), 1);
            }
            $barcodes[$f] = $texto;
        }
    }

    echo '<img src="imagens/p.gif" width="' . $fino . '" height="' . $altura . '" border="0" />';
    echo '<img src="imagens/b.gif" width="' . $fino . '" height="' . $altura . '" border="0" />';
    echo '<img src="imagens/p.gif" width="' . $fino . '" height="' . $altura . '" border="0" />';
    echo '<img src="imagens/b.gif" width="' . $fino . '" height="' . $altura . '" border="0" />';

    echo '<img ';

    $texto = $numero;

//                if ((strlen($texto) % 2) <> 0) {
    //                  $texto = '0' . $texto;
    //            }

    while (strlen($texto) > 0) {
        $i = round(substr($texto, 0, 2));
        $texto = substr($texto, strlen($texto) - (strlen($texto) - 2), (strlen($texto) - 2));

        if (isset($barcodes[$i])) {
            $f = $barcodes[$i];
        }

        for ($i = 1; $i < 11; $i+=2) {
            if (substr($f, ($i - 1), 1) == '0') {
                $f1 = $fino;
            } else {
                $f1 = $largo;
            }

            echo 'src="imagens/p.gif" width="' . $f1 . '" height="' . $altura . '" border="0">';
            echo '<img ';

            if (substr($f, $i, 1) == '0') {
                $f2 = $fino;
            } else {
                $f2 = $largo;
            }

            echo 'src="imagens/b.gif" width="' . $f2 . '" height="' . $altura . '" border="0">';
            echo '<img ';
        }
    }
    echo 'src="imagens/p.gif" width="' . $largo . '" height="' . $altura . '" border="0" />';
    echo '<img src="imagens/b.gif" width="' . $fino . '" height="' . $altura . '" border="0" />';
    echo '<img src="imagens/p.gif" width="1" height="' . $altura . '" border="0" />';
    echo"<br>";
    echo"<b>$numero</b>";
}

$sql = mysql_query("SELECT * FROM ficha")or die(mysql_error());

if (empty($sql)) {
    echo "Nenhum registro encontrado.";
}

while ($row = mysql_fetch_array($sql)) {
    $v_ficha_id = $row['ficha_id'];
    $v_ficha_data = $row['ficha_data'];
    $v_ficha_loja = $row['ficha_loja'];
    $v_ficha_ambiente = $row['ficha_ambiente'];
    $v_ficha_corredor = $row['ficha_corredor'];
    $v_ficha_lado = $row['ficha_lado'];
    $v_ficha_tipo_local = $row['ficha_tipo_local'];
    $v_ficha_id_local = $row['ficha_id_local'];
    $v_ficha_local = $row['ficha_local'];
    $v_ficha_coord = $row['ficha_coord'];
    $v_ficha_contagem = $row['ficha_contagem'];
    $v_cod_bar = $row['ficha_codbar'];
    ?>

    <html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br" xml:lang="pt-br">
        <head>    

            <!--<meta http-equiv="refresh" content="3; index.php">-->
            <link rel="shortcut icon" href="../img/favicon.ico"/>
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <meta name="description" content="">
                    <meta name="author" content="">
                        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

                            <title>FICHA DE CADASTRO</title>

                            <link rel="stylesheet" href="css/style.css">
                                <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
                                    <script src="bootstrap/js/jquery.min.js"></script>
                                    <script src="bootstrap/js/bootstrap.min.js"></script>
                                    </head>
                                    <body>
                                        <div class="container">

                                            <table class="table table-responsive">
                                                <thead>
                                                </thead>
                                                <tbody>
                                                    <tr>
    <?php echo"<td><img width='100px' height='60px' src='imagens/bg.png'/></td>"; ?>
                                                        <td>
                                                            <center>
                                                                <font size="2">FICHA DE INVENT�RIO - LOJA <?php echo"$v_ficha_loja"; ?></font>
                                                                <br>
                                                                    <font size="2"><?php $data = "$v_ficha_data"; ?></font>
                                                                    <font size="2">DATA:&nbsp;<?php echo date('d/m/Y', strtotime($data)); ?> </font>
                                                                    <font size="2">COORD:&nbsp;<?php echo"$v_ficha_coord"; ?></font>
                                                            </center>
                                                        </td>
                                                        <td>
                                                            <center> 
    <?php
    if ($v_ficha_tipo_local == 0) {
        geraCodigoBarra("$v_cod_bar");
    } else {

    }
    ?>
                                                            </center>
                                                        </td>
                                                    </tr>   
                                                </tbody>
                                            </table>

                                            <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td><font size="2">AMBIENTE:&nbsp;<?php echo"$v_ficha_ambiente"; ?></font></td>
                                                        <td><font size="2">CORREDOR:&nbsp;<?php echo"$v_ficha_corredor"; ?></font></td>
                                                        <td><font size="2"><?php echo"$v_ficha_lado"; ?></font></td>
                                                    </tr>
                                                    <tr>
                                                    </tr>   
                                                </tbody>
                                            </table> 


                                            <center><h5><b>&nbsp;<?php echo"$v_ficha_local</br>"; ?></h5></b></center>


                                            <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th><font size="2">CONTAGEM</font></th>
                                                        <th><font size="2">COLETAGEM</font></th>
                                                        <th><font size="2">CONFERENCIA</font></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td><font size="2">1:&nbsp;<?php echo"$v_ficha_contagem"; ?></font></td>
                                                        <td><font size="2">1:</font></td>
                                                        <td><font size="2">1:</font></td>
                                                    </tr>
                                                    <tr>
                                                        <td><font size="2">2:</font></td>
                                                        <td><font size="2">2:</font></td>
                                                        <td><font size="2">2:</font></td>
                                                    </tr>   
                                                </tbody>
                                            </table> 
                                            <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th><font size="2">OBSERVAÇÕES:</font></th>

                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td>&nbsp;</td>

                                                    </tr>  

                                                </tbody>
<?php } ?>
                                        </table> 



                                    </div>
                                </body>
                                </html>

1 answer

2


I’m not sure I understand the question but maybe LIMIT will solve.

$sql = mysql_query("SELECT * FROM ficha LIMIT 2")or die(mysql_error());
  • But there will only list, I want to list all and print 2 by pages.

  • I got it, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.