Вопрос

so I'm using this API (http://phptopdf.com/) to convert some php text to PDF. But I'm getting this error :-

Everything works fine until the first name, email. But, when I try to link in the orders, everything goes haywire.

Parse error: syntax error, unexpected T_WHILE in /home/a/public_html/pdf/packing_slip.php on line 124

Code

<?php
session_start();
include_once('phpToPDF.php') ;
include '../dbconnector.php';
include_once '../inc/inc.functions.php';
include '../dbpdo.php';
//require 'fbconfig.php';
if(!isset($_SESSION['email']))
{
    //not logged in.
    header('Location:http://macbuyback.co.uk/register');
    exit();
}
if((isset($_SESSION['logged']) && $_SESSION['logged']=1) || $user)
{
  //load the record for last orders
  $user_email = $_SESSION['email'];
  $date=date('Y-m-d');
  try
  {
    $statement = $conn->prepare("SELECT * From sales where email =? and orderDate = ?");
    $statement->execute(array(
      $user_email,
      $date));
    $statement->setFetchMode(PDO::FETCH_ASSOC);
  }
  catch(PDOException $e)
  {
    echo $e->getMessage();
  }

  //now get the customer details
  try
  {
    $statement2 = $conn->prepare("SELECT * From users where email = ?");
    $statement2->execute(array(
      $user_email));
    $statement2->setFetchMode(PDO::FETCH_ASSOC);
    $user_info = $statement2->fetch();
  }
  catch(PDOException $e)
  {
    echo $e->getMessage();
  }

  // Assign html code into php variable:-
    $html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Company</title>
<style type="text/css">
<!--
body {
  font-family:Tahoma;
}

img {
  border:0;
}

#page {
  width:800px;
  margin:0 auto;
  padding:15px;

}

#logo {
  float:left;
  margin:0;
}

#address {
  height:181px;
  margin-left:250px; 
}

table {
  width:100%;
}

td {
padding:5px;
}

tr.odd {
  background:#e1ffe1;
}
-->
</style>
</head>
<body>
<div id="page">
  <div id="logo">
    <a href="http://www.domain.co.uk/"><img src="http://www.domain.co.uk/pdf/logo.png"></a>
  </div><!--end logo-->

  <div id="address">

    <p>Company<br />
    <a href="mailto:info@company">info@company</a>
    <br /><br />
    Created on ' . date("Y-m-d") . ' 
    echo ' . $a . '
    </p>

  </div><!--end address-->

  <div id="content">
    <p>
      <strong>Customer Details</strong><br />
      Name: ' . $user_info['firstname'] . '<br />
      Email: ' . $_SESSION['email'] . '<br />

    <hr> ' . $a=1 .'
    <table>
      <tr>
        <td><strong>Serial</strong></td>
        <td><strong>Product Name</strong></td>
        <td><strong>Amount</strong></td>
        <td><strong>Pickup Date</strong></td>
      </tr>
      ' . while($row = $statement->fetch()){ . '
      '  if(($a%2) == 0){ . '
      <tr class="odd">
        <td> ' . $a . '</td>
        <td> ' . getProductNameFromId($row['pid']) . '</td>
        <td>' . $row['amount'] . '</td>
        <td>' . $row['shipmentdate'] . '</td>
      </tr>
      ' . $a++ }else{. '
      <tr class="even">
        <td> ' . $a . '</td>
        <td> ' . getProductNameFromId($row['pid']) . '</td>
        <td>' . $row['amount'] . '</td>
        <td>' . $row['shipmentdate'] . '</td>
      </tr>
      ' . $a++ }. '
      ' . } . '
    </table>
    <hr>
    <p>
      Thank you for your order!  This transaction will appear on your billing statement as "Your Company".<br />
      If you have any questions, please feel free to contact us at <a href="mailto:youremail@somewhere.com">youremail@somewhere.com</a>.
    </p>

    <hr>

    <p>
      <center><small>This communication is for the exclusive use of the addressee and may contain proprietary, confidential or privileged information. If you are not the intended recipient any use, copying, disclosure, dissemination or distribution is strictly prohibited.
      <br /><br />
      &copy; Your Company All Rights Reserved
      </small></center>
    </p>
  </div><!--end content-->
</div><!--end page-->
</body>

</html>';

phptopdf_html($html,'pdf', 'sample.pdf');
echo "<a href='pdf/sample.pdf'>Download PDF</a>";
}//login check
else
{
    header('Location:http://domain.co.uk/register');
    exit();
}
?>

What might be wrong ? Any suggestions are welcome.

Это было полезно?

Решение

Your while loop cannot be used inside a string concatenation.

$html ='.....
</tr>';
      while($row = $statement->fetch()){
        if(($a%2) == 0){
      $html .= '<tr class="odd">
        <td> ' . $a . '</td>
        <td> ' . getProductNameFromId($row['pid']) . '</td>
        <td>' . $row['amount'] . '</td>
        <td>' . $row['shipmentdate'] . '</td>
      </tr>';
      $a++; }else{
      $html .= '<tr class="even">
        <td> ' . $a . '</td>
        <td> ' . getProductNameFromId($row['pid']) . '</td>
        <td>' . $row['amount'] . '</td>
        <td>' . $row['shipmentdate'] . '</td>
      </tr>';
       $a++; }
       } 
   $html .= ' </table>
 .....';
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top