My code can print only separate invoice for each different product and I coded it for single product only but I need to add multiple product print in single paper. I am facing syntax error to change the loop body.How can I shift down the loop between “Purpose & Stamp” under the table?
here is the code so far
while($row = $orderItemResult->fetch_array()) {
$table .= '
<div class="container">
<div id="companyLogo" >
<img style="float: left; padding-right:5px;" height="50px" width="50px" src='.$company_logo.'>
</div>
<h4>'.$company_name.' </h4>
<p id="address">'.$company_address.' <br/>
</p>
<p>
<span class="#">Contact:</span> <span class="comcontact"> '.$company_phone.' </span><br/>
<span class="boldText">Email :</span> '.$com_email.' <br/>
<span class="boldText">Date :</span> '.$orderDate.', ['.$timenow.'] </p>
<br/> .
<span class="boldText">TOKEN NO : </span>'.$orderId.' <br/>
<span class="boldText">CUSTOMER ID NO : </span> '.$clientContact.' <br/>
<span class="boldText">Name : </span> '.$clientName.' <br/>
<span class="boldText">Mob : </span> '.$clientContact.' <br/>
<span class="boldText">Address : </span> '.$client_address.' <br/>
<span class="boldText">Purpose : </span> '.$row[4].' <br/>
<span class="boldText">Box No : </span> '.$row[7].' <br/>
<span class="boldText">Weight : </span> '.$row[6].' <br/>
<span class="boldText">Product Name : </span> '.$row[8].' <br/>
<span class="boldText">Stamp : </span> '.$stamp.' <br/>
<br/> .
<span class="boldText">TOTAL CHARGE : </span> '.$row[3].' <br/>
<span class="boldText">Payment Status : </span> '.$payment_status.' <br/>
<br/> .
<span class="boldText">Prepared By : </span> '.$userName.' <br/>
<br/>
<p id="address"> "Have a nice day.." </p>
</div>
';
$x++;
} // /while '.$row[4].' for product description and '.$row[5].' for brands
$table.= '
Advertisement
Answer
Preamble
It is quite unclear for me what you mean with shifting the loop down. What I suppose you want to achieve is to loop the lower section, not everything. This answer is based on that assumption. So here is my guess, cleaning up your code a little bit making use of PHPs templating power what makes it much easier to read.
Explanation
I am fetching the first row, using that data for the first elements. Where the loop occurs I’ve put the string %s
as a placeholder and fill it later with the real content. For the loop itself, a do while is perfect, because on the first run $row
stays what it is and the while runs until out of data.
$table = '';
$row = $orderItemResult->fetch_array();
$table .= <<<"_HTML"
<div class="container">
<div id="companyLogo" >
<img style="float: left; padding-right:5px;" height="50px" width="50px" src="{$company_logo}">
</div>
<h4>{$company_name}</h4>
<p id="address">{$company_address}<br/>
</p>
<p>
<span class="#">Contact:</span> <span class="comcontact">{$company_phone}</span><br/>
<span class="boldText">Email :</span>{$com_email}<br/>
<span class="boldText">Date :</span>{$orderDate}, [{$timenow}] </p>
<br/> .
<span class="boldText">TOKEN NO : </span>{$orderId}<br/>
<span class="boldText">CUSTOMER ID NO : </span>{$clientContact}<br/>
<span class="boldText">Name : </span>{$clientName}<br/>
<span class="boldText">Mob : </span>{$clientContact}<br/>
<span class="boldText">Address : </span>{$client_address}<br/>
<br/> .
<span class="boldText">TOTAL CHARGE : </span>{$row[3]}<br/>
<span class="boldText">Payment Status : </span>{$payment_status}<br/>
<span class="boldText">Purpose : </span>{$row[4]}<br/>
%s
<span class="boldText">Stamp : </span>{$stamp}<br/>
<br/> .
<span class="boldText">Prepared By : </span>{$userName}<br/>
<br/>
<p id="address"> "Have a nice day.." </p>
</div>
_HTML;
$loop = '';
do {
$loop .= <<<"_HTML"
<span class="boldText">Box No : </span>{$row[7]}<br/>
<span class="boldText">Weight : </span>{$row[6]}<br/>
<span class="boldText">Product Name : </span>{$row[8]}<br/>
_HTML;
} while ($row = $orderItemResult->fetch_array());
$table = sprintf($table, $loop);