【问题标题】:Getting variable from Mysql with a Loop on MPDF使用 MPDF 上的循环从 Mysql 获取变量
【发布时间】:2014-04-16 14:33:16
【问题描述】:

我正在尝试将数据库中的内容写入 MPDF 文件。我需要做一个循环,但我不能在“WriteHTML”部分内做,因为它不会识别为 PHP 代码。 如果我在循环外打印变量,它将无法识别整个数组。

<?php
session_start();

$id = $_SESSION['id'];
$email = $_SESSION['email'];
$pass = $_SESSION['pass'];
$nivel = $_SESSION['nivel'];

$funcao = $_SESSION['funcao'];
$area = $_SESSION['area'];
$nome = $_SESSION['nome'];
$apelido = $_SESSION['apelido'];
$chefe = $_SESSION['chefe'];
include 'includes/connect.php';
$id = $_SESSION['id'];


include "mpdf/mpdf.php";

这是循环:

    $pc=mysql_query("SELECT * from pp where id_user=$id" );
    $row = array();
    while ($data = mysql_fetch_array($pc)) $row[] = $data; 
        foreach ($row as $x){
        $id_producto = $x[0];
        $nome = $x[1];
        $preco = $x[2];
        $descricao = $x[3];
}

剩下的……

$html="
<center><img src='imagens/logo.png' width='100' height='100'></center>
<center><h3>Curriculo</h3></center>
Nome: $nome $apelido <br>
E-Mail: $email <bR>
Função: $funcao <br>
Área: $area <br>
Chefia: $chefe <br>


<h1>titulo</h1>
";


$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;

?>

谢谢

【问题讨论】:

    标签: php mysql mpdf


    【解决方案1】:

    对于你的循环:

        $pc=mysql_query("SELECT * from pp where id_user=$id" );
        $row = array();
        while ($data = mysql_fetch_array($pc)) $row[] = $data; 
            foreach ($row as $x){
            $id_producto = $x[0];
            $nome = $x[1];
            $preco = $x[2];
            $descricao = $x[3];
    }
    

    您所要做的就是添加您的 $mpdf->WriteHTML($html);

    <?php
    
    $html="
    <center><img src='imagens/logo.png' width='100' height='100'></center>
    <center><h3>Curriculo</h3></center>
    Nome: $nome $apelido <br>
    E-Mail: $email <bR>
    Função: $funcao <br>
    Área: $area <br>
    Chefia: $chefe <br>
    
    
    <h1>titulo</h1>
    ";
    
    $mpdf=new mPDF(); // Start the mPDF document
    $mpdf->WriteHTML($html); // Write out your initial HTML portion
    
            // Query to get the information you want
            $pc=mysql_query("SELECT * from pp where id_user=$id" );
            $row = array();
            while ($data = mysql_fetch_array($pc)) $row[] = $data; 
                foreach ($row as $x){
                $id_producto = $x[0];
                $nome = $x[1];
                $preco = $x[2];
                $descricao = $x[3];
            // Inside the loop you add new HTML lines to be written to the PDF
            // You can format this with normal HTML and output the data to the PDF
            // You should work with this section on your own to format it how you want
                $mpdf->WriteHTML("Producto: $id_producto");
                $mpdf->WriteHTML("Nome: $nome");
        }
    
    $mpdf->Output();
    exit;
    ?>
    

    【讨论】:

      【解决方案2】:

      你可以这样做

      $values='';
      
      
      foreach ($conditions as $condition) {
      $values .='<br>product name'.$condition['nome'].'<br>';
       $values .=<br>product id'.$condition['id_product'].'<br>';
      }
      $html="<center><img src='imagens/logo.png' width='100' height='100'>
      </center>
      <center><h3>Curriculo</h3></center>
      Nome: $nome $apelido <br>
      E-Mail: $email <bR>
      Função: $funcao <br>
      Área: $area <br>
      Chefia: $chefe <br>
      <h1>titulo</h1>
      $values ";
      $mpdf=new mPDF(); // Start the mPDF document
      $mpdf->WriteHTML($html); // Write out your initial HTML portion
      $mpdf->Output();
      exit;
      

      【讨论】:

        猜你喜欢
        • 2020-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-25
        • 2014-11-09
        • 2020-07-15
        • 1970-01-01
        相关资源
        最近更新 更多