I have a .php file that when I add three extra fields to it to be displayed (which begin with 'Client Vehicle'), it pushes down a 'div class' and it creates a lot of emtpy space. Things end up being on two pages instead of just one. Instead, there is a big empty space where my 'div class' used to be (its a table named 'invoice-details')
If I take away these fields, everything is spaced correctly. How can I add them and push the 'invoice-details' table back up into place?
Here are my css& php files:
.clearfix:after {
content: "";
display: table;
clear: both
}
a {
color: #375bc8;
text-decoration: underline
}
body {
position: relative;
width: 21cm;
height: 29.7cm;
margin: 0 auto;
color: #3A3A3A;
background: #FFFFFF;
font-family: sans-serif;
font-size: 14px
}
header {
padding: 10px 0;
margin-bottom: 30px
}
#logo {
text-align: right;
margin-bottom: 30px
}
#invoice-logo {
max-height: 125px;
text-align: right
}
.invoice-title {
color: #375bc8;
font-size: 2em;
line-height: 1.4em;
font-weight: normal;
margin: 20px 0
}
#company {
float: right;
text-align: right;
width: 40%
}
#client {
float: left;
width: 55%;
margin-right: 5%
}
.invoice-details {
text-align: right
}
.invoice-details table {
border-collapse: collapse;
border-spacing: 0;
text-align: right;
width: 40%;
margin: 0 0 0 auto;
font-size: 12px
}
.invoice-details table td {
width: auto;
margin: 0;
padding: 0 0 0.5em 0
}
table.item-table {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
margin-bottom: 20px;
font-size: 12px
}
table.item-table tr:nth-child(2n-1) td {
background: #F5F5F5
}
table.item-table th {
padding: 10px 15px;
border-bottom: 1px solid #606060;
white-space: nowrap;
text-align: left
}
table.item-table th.text-right {
text-align: right
}
table.item-table td {
padding: 10px 15px
}
table.item-table .invoice-sums {
text-align: right
}
footer {
color: #878787;
width: 100%;
border-top: 2px solid #878787;
padding: 8px 0
}
.text-right {
text-align: right
}
.text-red {
color: #ea5340
}
.text-green {
color: #77b632
}
<html lang="<?php echo lang('cldr'); ?>">
<head>
<meta charset="utf-8">
<title>
<?php echo lang( 'invoice'); ?>
</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/default/css/templates.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/default/css/custom-pdf.css">
</head>
<body>
<header class="clearfix">
<div id="logo">
<?php echo invoice_logo_pdf(); ?>
</div>
<div id="client">
<div>
<b><?php echo $invoice->client_name; ?></b>
</div>
<?php if ($invoice->client_vat_id) { echo '
<div>' . lang('vat_id_short') . ': ' . $invoice->client_vat_id . '</div>'; } if ($invoice->client_tax_code) { echo '
<div>' . lang('tax_code_short') . ': ' . $invoice->client_tax_code . '</div>'; } if ($invoice->client_address_1) { echo '
<div>' . $invoice->client_address_1 . '</div>'; } if ($invoice->client_address_2) { echo '
<div>' . $invoice->client_address_2 . '</div>'; } if ($invoice->client_city && $invoice->client_zip) { echo '
<div>' . $invoice->client_city . ' ' . $invoice->client_zip . '</div>'; } else { if ($invoice->client_city) { echo '
<div>' . $invoice->client_city . '</div>'; } if ($invoice->client_zip) { echo '
<div>' . $invoice->client_zip . '</div>'; } } if ($invoice->client_state) { echo '
<div>' . $invoice->client_state . '</div>'; } if ($invoice->client_country) { echo '
<div>' . get_country_name(lang('cldr'), $invoice->client_country) . '</div>'; } echo '
<br/>'; if ($invoice->client_phone) { echo '
<div>' . lang('phone_abbr') . ': ' . $invoice->client_phone . '</div>'; } ?>
<br/>
<p>
<?php echo 'Client Vehicle'; ?>
</p>
<p>
<?php echo 'Year'; ?>:
<?php echo $invoice->client_custom_year; ?></p>
<p>
<?php echo 'Make'; ?>:
<?php echo $invoice->client_custom_make; ?></p>
<p>
<?php echo 'Model'; ?>:
<?php echo $invoice->client_custom_model; ?></p>
</div>
<div id="company">
<div><b><?php echo $invoice->user_name; ?></b>
</div>
<?php if ($invoice->user_vat_id) { echo '
<div>' . lang('vat_id_short') . ': ' . $invoice->user_vat_id . '</div>'; } if ($invoice->user_tax_code) { echo '
<div>' . lang('tax_code_short') . ': ' . $invoice->user_tax_code . '</div>'; } if ($invoice->user_address_1) { echo '
<div>' . $invoice->user_address_1 . '</div>'; } if ($invoice->user_address_2) { echo '
<div>' . $invoice->user_address_2 . '</div>'; } if ($invoice->user_city && $invoice->user_zip) { echo '
<div>' . $invoice->user_city . ' ' . $invoice->user_zip . '</div>'; } else { if ($invoice->user_city) { echo '
<div>' . $invoice->user_city . '</div>'; } if ($invoice->user_zip) { echo '
<div>' . $invoice->user_zip . '</div>'; } } if ($invoice->user_state) { echo '
<div>' . $invoice->user_state . '</div>'; } if ($invoice->user_country) { echo '
<div>' . get_country_name(lang('cldr'), $invoice->user_country) . '</div>'; } echo '
<br/>'; if ($invoice->user_phone) { echo '
<div>' . lang('phone_abbr') . ': ' . $invoice->user_phone . '</div>'; } if ($invoice->user_fax) { echo '
<div>' . lang('fax_abbr') . ': ' . $invoice->user_fax . '</div>'; } ?>
</div>
</header>
<main>
<div class="invoice-details clearfix">
<table>
<tr>
<td>
<?php echo lang( 'invoice_date') . ':'; ?>
</td>
<td>
<?php echo date_from_mysql($invoice->invoice_date_created, true); ?></td>
</tr>
<tr>
<td>
<?php echo lang( 'due_date') . ': '; ?>
</td>
<td>
<?php echo date_from_mysql($invoice->invoice_date_due, true); ?></td>
</tr>
<tr>
<td>
<?php echo lang( 'amount_due') . ': '; ?>
</td>
<td>
<?php echo format_currency($invoice->invoice_balance); ?></td>
</tr>
<?php if ($payment_method): ?>
<tr>
<td>
<?php echo lang( 'payment_method') . ': '; ?>
</td>
<td<?php echo $payment_method->payment_method_name; ?></td>
</tr>
<?php endif; ?>
</table>
</div>
<h1 class="invoice-title"><?php echo lang('invoice') . ' ' . $invoice->invoice_number; ?></h1>
<table class="item-table">
<thead>
<tr>
<th class="item-name">
<?php echo lang( 'item'); ?>
</th>
<th class="item-desc">
<?php echo lang( 'description'); ?>
</th>
<th class="item-amount text-right">
<?php echo lang( 'qty'); ?>
</th>
<th class="item-price text-right">
<?php echo lang( 'price'); ?>
</th>
<?php if ($show_discounts) : ?>
<th class="item-discount text-right">
<?php echo lang( 'discount'); ?>
</th>
<?php endif; ?>
<th class="item-total text-right">
<?php echo lang( 'total'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item) { ?>
<tr>
<td>
<?php echo $item->item_name; ?></td>
<td>
<?php echo nl2br($item->item_description); ?></td>
<td class="text-right">
<?php echo format_amount($item->item_quantity); ?>
</td>
<td class="text-right">
<?php echo format_currency($item->item_price); ?>
</td>
<?php if ($show_discounts) : ?>
<td class="text-right">
<?php echo format_currency($item->item_discount); ?>
</td>
<?php endif; ?>
<td class="text-right">
<?php echo format_currency($item->item_subtotal); ?>
</td>
</tr>
<?php } ?>
</tbody>
<tbody class="invoice-sums">
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<?php echo lang( 'subtotal'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_item_subtotal); ?></td>
</tr>
<?php if ($invoice->invoice_item_tax_total > 0) { ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<?php echo lang( 'item_tax'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_item_tax_total); ?>
</td>
</tr>
<?php } ?>
<?php foreach ($invoice_tax_rates as $invoice_tax_rate) : ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<?php echo $invoice_tax_rate->invoice_tax_rate_name . ' (' . $invoice_tax_rate->invoice_tax_rate_percent . '%)'; ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice_tax_rate->invoice_tax_rate_amount); ?>
</td>
</tr>
<?php endforeach ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<b><?php echo lang('total'); ?></b>
</td>
<td class="text-right">
<b><?php echo format_currency($invoice->invoice_total); ?></b>
</td>
</tr>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<?php echo lang( 'paid'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_paid); ?>
</td>
</tr>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?>class="text-right">
<b><?php echo lang('balance'); ?></b>
</td>
<td class="text-right">
<b><?php echo format_currency($invoice->invoice_balance); ?></b>
</td>
</tr>
</tbody>
</table>
</main>
<footer>
<?php if ($invoice->invoice_terms) : ?>
<div class="notes">
<b><?php echo lang('terms'); ?></b>
<br/>
<?php echo nl2br($invoice->invoice_terms); ?>
</div>
<?php endif; ?>
</footer>
</body>
</html>
Here is my updated .php file with the added div. The new revision only works down to the new div I added as I guess because this is nested?
<html lang="<?php echo lang('cldr'); ?>">
<head>
<meta charset="utf-8">
<title><?php echo lang('invoice'); ?></title>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/default/css/templates.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/default/css/custom-pdf.css">
</head>
<body>
<header class="clearfix">
<div id="logo">
<?php echo invoice_logo_pdf(); ?>
</div>
<div id="client">
<div>
<b><?php echo $invoice->client_name; ?></b>
</div>
<?php if ($invoice->client_vat_id) {
echo '<div>' . lang('vat_id_short') . ': ' . $invoice->client_vat_id . '</div>';
}
if ($invoice->client_tax_code) {
echo '<div>' . lang('tax_code_short') . ': ' . $invoice->client_tax_code . '</div>';
}
if ($invoice->client_address_1) {
echo '<div>' . $invoice->client_address_1 . '</div>';
}
if ($invoice->client_address_2) {
echo '<div>' . $invoice->client_address_2 . '</div>';
}
if ($invoice->client_city && $invoice->client_zip) {
echo '<div>' . $invoice->client_city . ' ' . $invoice->client_zip . '</div>';
} else {
if ($invoice->client_city) {
echo '<div>' . $invoice->client_city . '</div>';
}
if ($invoice->client_zip) {
echo '<div>' . $invoice->client_zip . '</div>';
}
}
if ($invoice->client_state) {
echo '<div>' . $invoice->client_state . '</div>';
}
if ($invoice->client_country) {
echo '<div>' . get_country_name(lang('cldr'), $invoice->client_country) . '</div>';
}
echo '<br/>';
if ($invoice->client_phone) {
echo '<div>' . lang('phone_abbr') . ': ' . $invoice->client_phone . '</div>';} ?>
<br>
<div>
<b><?php echo '<u>Client Vehicle</u>'; ?>:</b>
<br>
<?php echo 'Year'; ?>:
<?php echo $invoice->client_custom_year; ?>
</br>
<br>
<?php echo 'Make'; ?>:
<?php echo $invoice->client_custom_make; ?>
</br>
<br>
<?php echo 'Model'; ?>:
<?php echo $invoice->client_custom_model; ?>
</br>
</div>
</div>
<div id="company">
<div><b><?php echo $invoice->user_name; ?></b></div>
<?php if ($invoice->user_vat_id) {
echo '<div>' . lang('vat_id_short') . ': ' . $invoice->user_vat_id . '</div>';
}
if ($invoice->user_tax_code) {
echo '<div>' . lang('tax_code_short') . ': ' . $invoice->user_tax_code . '</div>';
}
if ($invoice->user_address_1) {
echo '<div>' . $invoice->user_address_1 . '</div>';
}
if ($invoice->user_address_2) {
echo '<div>' . $invoice->user_address_2 . '</div>';
}
if ($invoice->user_city && $invoice->user_zip) {
echo '<div>' . $invoice->user_city . ' ' . $invoice->user_zip . '</div>';
} else {
if ($invoice->user_city) {
echo '<div>' . $invoice->user_city . '</div>';
}
if ($invoice->user_zip) {
echo '<div>' . $invoice->user_zip . '</div>';
}
}
if ($invoice->user_state) {
echo '<div>' . $invoice->user_state . '</div>';
}
if ($invoice->user_country) {
echo '<div>' . get_country_name(lang('cldr'), $invoice->user_country) . '</div>';
}
echo '<br/>';
if ($invoice->user_phone) {
echo '<div>' . lang('phone_abbr') . ': ' . $invoice->user_phone . '</div>';
}
if ($invoice->user_fax) {
echo '<div>' . lang('fax_abbr') . ': ' . $invoice->user_fax . '</div>';
}
?>
</div>
</header>
<main>
<div class="invoice-details clearfix">
<table>
<tr>
<td><?php echo lang('invoice_date') . ':'; ?></td>
<td><?php echo date_from_mysql($invoice->invoice_date_created, true); ?></td>
</tr>
<tr>
<td><?php echo lang('due_date') . ': '; ?></td>
<td><?php echo date_from_mysql($invoice->invoice_date_due, true); ?></td>
</tr>
<tr>
<td><?php echo lang('amount_due') . ': '; ?></td>
<td><?php echo format_currency($invoice->invoice_balance); ?></td>
</tr>
<?php if ($payment_method): ?>
<tr>
<td><?php echo lang('payment_method') . ': '; ?></td>
<td<?php echo $payment_method->payment_method_name; ?></td>
</tr>
<?php endif; ?>
</table>
</div>
<h1 class="invoice-title"><?php echo lang('invoice') . ' ' . $invoice->invoice_number; ?></h1>
<table class="item-table">
<thead>
<tr>
<th class="item-name"><?php echo lang('item'); ?></th>
<th class="item-desc"><?php echo lang('description'); ?></th>
<th class="item-amount text-right"><?php echo lang('qty'); ?></th>
<th class="item-price text-right"><?php echo lang('price'); ?></th>
<?php if ($show_discounts) : ?>
<th class="item-discount text-right"><?php echo lang('discount'); ?></th>
<?php endif; ?>
<th class="item-total text-right"><?php echo lang('total'); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($items as $item) { ?>
<tr>
<td><?php echo $item->item_name; ?></td>
<td><?php echo nl2br($item->item_description); ?></td>
<td class="text-right">
<?php echo format_amount($item->item_quantity); ?>
</td>
<td class="text-right">
<?php echo format_currency($item->item_price); ?>
</td>
<?php if ($show_discounts) : ?>
<td class="text-right">
<?php echo format_currency($item->item_discount); ?>
</td>
<?php endif; ?>
<td class="text-right">
<?php echo format_currency($item->item_subtotal); ?>
</td>
</tr>
<?php } ?>
</tbody>
<tbody class="invoice-sums">
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<?php echo lang('subtotal'); ?>
</td>
<td class="text-right"><?php echo format_currency($invoice->invoice_item_subtotal); ?></td>
</tr>
<?php if ($invoice->invoice_item_tax_total > 0) { ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<?php echo lang('item_tax'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_item_tax_total); ?>
</td>
</tr>
<?php } ?>
<?php foreach ($invoice_tax_rates as $invoice_tax_rate) : ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<?php echo $invoice_tax_rate->invoice_tax_rate_name . ' (' . $invoice_tax_rate->invoice_tax_rate_percent . '%)'; ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice_tax_rate->invoice_tax_rate_amount); ?>
</td>
</tr>
<?php endforeach ?>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<b><?php echo lang('total'); ?></b>
</td>
<td class="text-right">
<b><?php echo format_currency($invoice->invoice_total); ?></b>
</td>
</tr>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<?php echo lang('paid'); ?>
</td>
<td class="text-right">
<?php echo format_currency($invoice->invoice_paid); ?>
</td>
</tr>
<tr>
<td <?php echo($show_discounts ? 'colspan="5"' : 'colspan="4"'); ?> class="text-right">
<b><?php echo lang('balance'); ?></b>
</td>
<td class="text-right">
<b><?php echo format_currency($invoice->invoice_balance); ?></b>
</td>
</tr>
</tbody>
</table>
</main>
<footer>
<?php if ($invoice->invoice_terms) : ?>
<div class="notes">
<b><?php echo lang('terms'); ?></b><br/>
<?php echo nl2br($invoice->invoice_terms); ?>
</div>
<?php endif; ?>
</footer>
</body>
</html>
Add the div tag for the new added elements
<div>
<p>
<?php echo 'Client Vehicle'; ?>
</p>
<p>
<?php echo 'Year'; ?>:
<?php echo $invoice->client_custom_year; ?></p>
<p>
<?php echo 'Make'; ?>:
<?php echo $invoice->client_custom_make; ?></p>
<p>
<?php echo 'Model'; ?>:
<?php echo $invoice->client_custom_model; ?></p>
</div>
Related
The code does not display the data.
I try to display the values of each ReportItems in a table.
The code does not display any error when I call it.
Please can someone help me? Thank you very much.
//The code does not display the data.
I try to display the values of each ReportItems in a table.
The code does not display any error when I call it.
Please can someone help me? Thank you very much.
<?php
$url =
"https://api.booker.com/v4.1/merchant/location/.../Report/DailySales?access_token={...}&date_from={...}&date_to={...}";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Ocp-Apim-Subscription-Key: {...}",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
$obj = json_decode($resp, true);
$i = 0;
$nw= array_filter($obj['ReportItems'], function($v,$k){
return in_array($k, ['Date', 'DateOffset', 'Discount', 'Discount', 'GiftCertificate', 'GiftCertificateRefund', 'Orders', 'Refunds', 'Services', 'SubTotal', 'Tax', 'Tip', 'Total']);
}, ARRAY_FILTER_USE_BOTH);
$i=0;
foreach($nw as $k => $v){
$last = $i !== count($nw)-1 ? ','.PHP_EOL : '';
echo "\"$k\": \"$v\"".$last;
$i++;
}
$arrays = json_decode($resp);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSON</title>
<link rel="shortcut icon" type="image/x-icon" href="icon.ico">
<meta name="description" content="HTML, PHP, JSON, REST API">
<style>table, th, td {border: 1px solid black;}</style>
</head>
<body>
<?php foreach ($nw as $k => $v) { ?>
<div style="width:200px;border:2px solid black;height:20px;">
<?php echo 'Date: ' . $v -> Date ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'DateOffset: ' . $v -> DateOffset ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'Discount: ' . $v -> Discount ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'GiftCertificate: ' . $v -> GiftCertificate ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'GiftCertificateRefund: ' . $v -> GiftCertificateRefund ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'Orders: ' . $v -> Orders ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'Refund: ' . $v -> Refund ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'Services: ' . $v -> Services ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'SubTotal: ' . $v -> SubTotal ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'Tax: ' . $v -> Tax ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'Tip: ' . $v -> Tip ?> </div><br />
<div style="width:200px;border:2px solid black;height:20px;"> <?php echo 'Total: ' . $v -> Total ?> </div><br />
<br />
<?php } ?>
<table style="width:100%"; class="data-table">
<tr>
<th>Date:</th>
<th>DateOffset:</th>
<th>Discount:</th>
<th>GiftCertificate:</th>
<th>GiftCertificateRefund:</th>
<th>Orders:</th>
<th>Refund:</th>
<th>Services:</th>
<th>SubTotal:</th>
<th>Tax:</th>
<th>Tip:</th>
<th>Total:</th>
</tr>
<?php foreach ($nw as $k => $v) { ?>
<tr>
<td><?php echo $v -> Date ?> </td>
<td><?php echo $v -> DateOffset ?> </td>
<td><?php echo $v -> Discount ?> </td>
<td><?php echo $v -> GiftCertificate ?> </td>
<td><?php echo $v -> GiftCertificateRefund ?> </td>
<td><?php echo $v -> Orders ?> </td>
<td><?php echo $v -> Refund ?> </td>
<td><?php echo $v -> Services ?> </td>
<td><?php echo $v -> SubTotal ?> </td>
<td><?php echo $v -> Tax ?> </td>
<td><?php echo $v -> Tip ?> </td>
<td><?php echo $v -> Total ?> </td>
</tr>
<?php } ?>
</table>
</body>
</html>
Please can someone help me?
Thank you.
spent hours unsuccessfully trying to figure this out, just not a good coder. I have 2 headings called title and date and I'm trying to stop them from repeating before every row. I just want the heading once at the top. What do I have to change to accomplish this. Thanks!!!! Use bitcoin to search.
<thead>
<tr>
<th class='table-header' width='20%'>Title</th>
<th class='table-header' width='5%'>Date</th>
</tr>
</thead>
<?php
define("ROW_PER_PAGE",15);
require_once('db.php');
?>
<html>
<head>
<style>
body{width:615px;font-family:arial;letter-spacing:1px;line-height:20px;}
.tbl-qa{width: 100%;font-size:0.9em;background-color: #f5f5f5;}
.tbl-qa th.table-header {padding: 5px;text-align: left;padding:10px;}
.tbl-qa .table-row td {padding:10px;background-color: #FDFDFD;vertical-align:top;}
.button_link {color:#FFF;text-decoration:none; background-color:#428a8e;padding:10px;}
#keyword{border: #CCC 1px solid; border-radius: 4px; padding: 7px;background:url("demo-search-icon.png") no-repeat center right 7px;}
.btn-page{margin-right:10px;padding:5px 10px; border: #CCC 1px solid; background:#FFF; border-radius:4px;cursor:pointer;}
.btn-page:hover{background:#F0F0F0;}
.btn-page.current{background:#F0F0F0;}
</style>
</head>
<body>
<?php
$search_keyword = '';
if(!empty($_POST['search']['keyword'])) {
$search_keyword = $_POST['search']['keyword'];
$sql = 'SELECT * FROM posts WHERE post_title LIKE :keyword OR description LIKE :keyword OR post_at LIKE :keyword ORDER BY id DESC ';
/* Pagination Code starts */
$per_page_html = '';
$page = 1;
$start=0;
if(!empty($_POST["page"])) {
$page = $_POST["page"];
$start=($page-1) * ROW_PER_PAGE;
}
$limit=" limit " . $start . "," . ROW_PER_PAGE;
$pagination_statement = $pdo_conn->prepare($sql);
$pagination_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pagination_statement->execute();
$row_count = $pagination_statement->rowCount();
if(!empty($row_count)){
$per_page_html .= "<div style='text-align:center;margin:20px 0px;'>";
$page_count=ceil($row_count/ROW_PER_PAGE);
if($page_count>1) {
for($i=1;$i<=$page_count;$i++){
if($i==$page){
$per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page current" />';
} else {
$per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page" />';
}
}
}
$per_page_html .= "</div>";
}
$query = $sql.$limit;
$pdo_statement = $pdo_conn->prepare($query);
$pdo_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pdo_statement->execute();
$result = $pdo_statement->fetchAll();
}
?>
<form name='frmSearch' action='' method='post'>
<div style='text-align:right;margin:20px 0px;'><input type='text' name='search[keyword]' value="<?php echo $search_keyword; ?>" id='keyword' maxlength='25'></div>
<?php
if(!empty($result)) {
foreach($result as $row) {
?>
<table class='tbl-qa'>
<thead>
<tr>
<th class='table-header' width='20%'>Title</th>
<th class='table-header' width='5%'>Date</th>
</tr>
</thead>
<tbody id='table-body'>
<tr class='table-row'>
<td><a style="text-decoration: none;" href="<?php echo $row['description']; ?>">
<?php echo $row['post_title']; ?></a></td>
<td><?php echo $row['post_at']; ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php echo $per_page_html; ?>
</form>
</body>
</html>
This way it will works:
Array to test (use your $result in your case)
$result=array(
array('post_title'=>'title 1','post_at'=>'at 1'),
array('post_title'=>'title 2','post_at'=>'at 2'),
array('post_title'=>'title 3','post_at'=>'at 3'),
)
Html:
<table class='tbl-qa'>
<tr>
<th class='table-header' width='20%'>Title</th>
<th class='table-header' width='5%'>Date</th>
</tr>
<?php
if(!empty($result)) {
foreach($result as $row) {
?>
<tr class='table-row'>
<td><a style="text-decoration: none;" href="<?php echo $row['description']; ?>">
<?php echo $row['post_title']; ?></a></td>
<td><?php echo $row['post_at']; ?></td>
</tr>
<?php
}
?>
<?php
}
?>
As you can see, the header if written just once because it is out of the loop whilst the row inside the loop will be repeated.
Finally close the table out of the loop.
I hav run into a problem - I am not that familiar with cakephp - but I have taken over a project (A webshop project) - and now I have a bit of a problem - I have a field (tracking id for the package) which writes to DB - that works great - but here is the trouble - when I click the button and save the tracking number to the DB - I wan't the system to send an email to the customer with the tracking id.
I can get the system to send a mail - but there is no tracking number on so I guess the email is send before the DB i updated.
Hope someone can point me in the right direction
public function send($order_id = null, $is_resolved = true)
{
if($this->request->is('post'))
{
$this->Order->id = $this->request->data['Order']['id'];
$this->Order->saveField('state', 'resolved');
$this->Order->saveField('date_resolved', date('Y-m-d H:i:s'));
$this->Order->saveField('delivery_label', $this->request->data['Order']['delivery_label']);
$this->Session->setFlash('Ordren er nu sat til "Sendt".'.$this->Session->read('Message.success.message'), null, array(), 'success');
$this->redirect(array('controller' => 'orders', 'action' => 'index'));
}
$order = $this->Order->find('first', array('conditions' => array('Order.id' => $order_id, 'Order.state' => 'packed'), 'recursive' => 4));
// Does the item exist?
if(empty($order))
{
// Tell the user this item did not exist
$this->Session->setFlash('Ordren findes ikke.'.$this->Session->read('Message.warning.message'), null, array(), 'warning');
return $this->redirect($this->referer());
}
if($is_resolved) {
// Send the email receipt
$Email = new CakeEmail('receipt');
$Email->to($order['Customer']['email_address']);
$Email->template('receipt_send')->viewVars( array('order' => $order));
$Email->send();
}
$this->set('order', $order);
}
Here is the receipt_send code
<table style="width:100%; margin-bottom:30px; border-collapse: collapse; color:#777;">
<tr style="vertical-align:middle; border-bottom:1px solid #777;">
<td colspan="3" style="width:45%; padding:10px 0;"><?php echo $this->Html->image('logo.png', array('style' => 'height:50px; margin-top:-15px; vertical-align:middle;', 'fullBase' => true)); ?></td>
</tr>
<tr style="font-size:1em; border-bottom:1px solid #777;">
<td style="padding: 5px 0;"><strong>Kvittering</strong> fra Bundgaards Garn</td>
<td style="padding: 5px 0;">Ordre nr. <strong><?php echo $order['Order']['id']; ?></strong></td>
</tr>
<p style="width:50%; float:right;">Din ordre er afsendt og har fået trackingnummer: <strong><?php echo $order['Order']['delivery_label']; ?></strong></p>
<table style="text-align: left; width:100%; border-collapse: collapse;">
<tr style="border-bottom:2px solid #dddddd;">
<th style="width:35%; padding: 10px 0;">Vare</th>
<th style="width:25%; padding: 10px 0;">Antal</th>
<th style="width:20%; padding: 10px 0; text-align:right;">Pris</th>
<th style="width:20%; padding: 10px 0; text-align:right;">Total</th>
</tr>
<?php foreach ($order['OrderItem'] as $key => $order_item): ?>
<tr style="border-bottom:1px solid #dddddd;">
<!-- PRODCUT LINK -->
<td style="padding: 10px 0; vertical-align: middle;">
<?php if($order_item['yarn_batch_id'] != 0) : ?>
<?php echo $order_item['YarnBatch']['YarnVariant']['Yarn']['name'] . ' - ' . $order_item['YarnBatch']['YarnVariant']['color_code'] . '-' . $order_item['YarnBatch']['batch_code']; ?>
<?php elseif($order_item['needle_variant_id'] != 0) : ?>
<?php echo $order_item['NeedleVariant']['Needle']['name'] . ' - ' . $order_item['NeedleVariant']['product_code']; ?>
<?php elseif($order_item['recipe_id'] != 0) : ?>
Print af <?php echo $order_item['Recipe']['name']; ?>
<?php elseif($order_item['color_sample_id'] != 0) : ?>
Farveprøve af <?php echo $order_item['ColorSample']['name']; ?>
<?php endif; ?>
</td>
<!-- PRODCUT LINK COLLAPSE -->
<td style="padding: 10px 0; vertical-align: middle;">
<?php echo $order_item['amount']; ?>
</td>
<td style="padding: 10px 0; vertical-align: middle; text-align:right;">
<?php if($order_item['yarn_batch_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['YarnBatch']['price'], 'DKK');?>
<?php elseif($order_item['needle_variant_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['NeedleVariant']['price'], 'DKK');?>
<?php elseif($order_item['recipe_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['Recipe']['price'], 'DKK');?>
<?php elseif($order_item['color_sample_id'] != 0) : ?>
<?php echo $this->Number->currency($order_item['ColorSample']['price'], 'DKK');?>
<?php endif; ?>
</td>
<td style="padding: 10px 0; vertical-align: middle; text-align:right;" >
<?php echo $this->Number->currency($order_item['price'], 'DKK');?>
<?php if($order_item['saving'] > 0) : ?>
<br/>
<span style="color:#5cb85c;"><?php echo $this->Number->currency($order_item['saving'], 'DKK');?>´</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="2"/>
<td style="text-align:right;">
<p>Levering</p>
<?php if($order['Order']['saving'] > 0) : ?>
<p>Rabat</p>
<?php endif; ?>
<p><strong>Subtotal</strong></p>
<p><strong>Moms</strong></p>
</td>
<td style="text-align:right;">
<p><?php echo $this->Number->currency($order['Order']['shipping_price'], 'DKK');?></p>
<?php if($order['Order']['saving'] > 0) : ?>
<p style="color:#5cb85c;"><strong><?php echo $this->Number->currency($order['Order']['saving'], 'DKK');?></strong></p>
<?php endif; ?>
<p><strong><?php echo $this->Number->currency($order['Order']['sub_total'], 'DKK');?></strong></p>
<p><strong><?php echo $this->Number->currency($order['Order']['tax'], 'DKK');?></strong></p>
</td>
</tr>
<tr>
<td colspan="2"/>
<td style="text-align:right;">
<h4>Total:</h4>
</td>
<td style="text-align:right; color:#900000;">
<h4><strong><?php echo $this->Number->currency($order['Order']['price'], 'DKK');?></strong></h4>
</td>
</tr>
</table>
<div style="width:50%; float:left;">
<h4>Ordren sendes til:</h4>
<p>
<strong><?php echo $order['Customer']['first_name'] . ' ' . $order['Customer']['last_name']; ?></strong><br>
<?php echo $order['Customer']['ShippingAddress']['street'] . ' ' .
$order['Customer']['ShippingAddress']['zip_code'] . ' ' .
$order['Customer']['ShippingAddress']['city_name']?><br>
<?php echo $order['Customer']['email_address']; ?><br>
<?php echo $order['Customer']['phone_number']; ?><br>
</p>
</div>
<div style="width:50%; float:left;">
<?php if(!empty($order['Order']['customer_note'])) : ?>
<h4>Note til forhandleren:</h4>
<p>
<?php echo $order['Order']['customer_note']; ?>
</p>
<?php endif; ?>
</div>
<hr style="width:100%; border: 0; border-bottom: 1px solid #ddd;">
<p style="color:#999; font-size:0.8em;">
<strong>Bundggards Garn</strong> <br/>
<a style="color:#777;" href="https://bundgaardsgarn.dk">bundgaardsgarn.dk</a> <br/>
kontakt#bundgaardsgarn.dk <br/>
Saltumvej 46 9700 Brønderslev <br/>
30369522 <br/>
<i>CVR:</i> 34526826 <br/>
</p>
Got it to work by creating a controller and make a button to the information.... Works like a charm.
Below is my while loop table, currently it's showing just one item per row. I can't seem to figure out how to get 4 items/columns to show before it shows a new row below. Any help with this would be much appreciated, thank you!
Jerome
<table style="background-color: white">
<?php
while ($row = mysql_fetch_array($rs)) {
?>
Collapse | Copy Code
<tr <?php //if ($i % 2) echo ' style="background-color: #ECECFB;"';?>>
<td class="rows"><font color="4D4D4D" size="3"><? echo '<a type="video/x-matroska" href=file://///'.$row["Link"].' target=blank>'.$row["Name"].'</a>' ?><br />
<? echo '<a type="video/x-matroska" href=file://///'.$row["Link"].' target=blank><img src='.$row["Picture"].' height=210px width=141px></a>' ?><br />
<? echo '('.$row["Type"].')' ?> <? echo $row["Year"] ?> <? echo $row["Rating"] ?> <? echo date('H:i', mktime(0,$row["Length"])); ?><br />
<? echo $row["Genre"] ?><br />
<? if ($row["Queue"]==='x') {
echo
"<center><a title=Remove From Watch List href='deletequeue.php?id=".$row['ID']."'><img align='center' width='20px' src='http://www.ourlittlelucas.net/ourflix/images/Minus.png'></a></td></font></center>";
}
else {
echo "<center><a title=Add To Watch List href='addqueue.php?id=".$row['ID']."'><img align='center' width='20px' src='http://www.ourlittlelucas.net/ourflix/images/Plus.png'></a></td></font></center>";
}
?>
</td></tr></font>
<?php $i++?>
<?php
}
?>
</table>
Try it
<table style="background-color: white">
<?php
while ($row = mysql_fetch_array($rs))
{
?>
Collapse | Copy Code
<tr <?php //if ($i % 2) echo ' style="background-color: #ECECFB;"';?>>
<td class="rows">
<font color="4D4D4D" size="3"><?php echo '<a type="video/x-matroska" href=file://///'.$row["Link"].' target=blank>'.$row["Name"].'</a>'; ?><br />
<?php echo '<a type="video/x-matroska" href=file://///'.$row["Link"].' target=blank><img src='.$row["Picture"].' height=210px width=141px></a>'; ?><br />
<?php echo '('.$row["Type"].')' ?>
<?php echo $row["Year"] ;?>
<?php echo $row["Rating"]; ?>
<?php echo date('H:i', mktime(0,$row["Length"])); ?><br />
<?php echo $row["Genre"] ;?><br />
<?php
if ($row["Queue"]=="x") {
echo
"<center><a title=Remove From Watch List href='deletequeue.php?id=".$row['ID']."'><img align='center' width='20px' src='http://www.ourlittlelucas.net/ourflix/images/Minus.png'></a></td></font></center>";
}
else
{
echo "<center><a title=Add To Watch List href='addqueue.php?id=".$row['ID']."'><img align='center' width='20px' src='http://www.ourlittlelucas.net/ourflix/images/Plus.png'></a></td></font></center>";
}
?>
</td></tr></font>
<?php $i++?>
<?php
}
?>
</table>
<?php
$sql = 'SELECT gamedate, gametime, homeschool, visitorschool FROM my_table WHERE WEEKOFYEAR(gamedate)=WEEKOFYEAR(NOW()) ORDER BY gamedate';
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
if(mysql_num_rows($result)>0) {
?>
<table style="width: 300px; padding: 0; margin-left: -16px;" cellpadding="7px">
<tbody>
<tr><td valign="top"><img src="images/cobrasschedule.png"/></td></tr>
<?php
mysql_data_seek($result, 0);
$day = ' ';
while ($row = mysql_fetch_assoc($result)) {
if (date('l, F d, Y', strtotime($row['gamedate'])) !== $day) {
$day=date('l, F d, Y', strtotime($row['gamedate']));
?>
<tr>
<td colspan="2" style="background-color:#D3BC9A; color:white;text-transform:uppercase; padding-left:25px;"><strong><?= $day?></strong></td>
</tr>
<?php } ?>
<tr>
<?php if ($row['sporttype'] == 'Baseball'): ?>
<td colspan="2" style="background-color:#D3BC9A; color:white;text-transform:uppercase; padding-left:25px;"><strong>BASEBALL</strong></td>
<?php elseif ($row['sporttype'] == 'MBasketball'): ?>
<td colspan="2" style="background-color:#D3BC9A; color:white;text-transform:uppercase; padding-left:25px;"><strong>MEN'S BASKETBALL</strong></td>
<?php elseif ($row['sporttype'] == 'Equine'): ?>
<td colspan="2" style="background-color:#D3BC9A; color:white;text-transform:uppercase; padding-left:25px;"><strong>EQUINE</strong></td>
<?php endif; ?>
</tr>
<tr>
<?php if ($row['homeschool'] == 'Virginia Intermont College - VA'): ?>
<td><p style="text-shadow: none; margin-bottom: -7px;"><strong><?php echo $row['homeschool'];?>vs.</strong><br ><?php echo $row['visitorschool'];?></p></td>
<?php else: ?>
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['visitorschool'];?>#<br ><?php echo $row['homeschool'];?></p></td>
<?php endif; ?>
<?php if ($row['homescore'] != ' ' and $row['homeschool'] == 'Virginia Intermont College - VA'): ?>
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['homescore'];?><br ><?php echo $row['visitorscore'];?></p></td>
<?php elseif ($row['homescore'] != ' ' and $row['homeschool'] != 'Virginia Intermont College - VA'): ?>
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['visitorscore'];?><br ><?php echo $row['homescore'];?></p></td>
<?php elseif ($row['score'] != ' '): ?>
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['score'];?></p></td>
<?php elseif ($row['score'] == ' ' and $row['homescore'] == ' '): ?>
<td><p style="text-shadow: none; margin-bottom: -7px;"><?php echo $row['gametime'];?></p></td>
<?php endif; ?>
</tr>
<?php
$day=date('l, F d, Y', strtotime($row['gamedate']));
}
}
?>
</tbody>
</table>
<?php
} else {?>
<span style="vertical-align:top;margin-left:-16px;padding:0;"><img src="images/cobrasschedule.png" border="0"/></span>
<?php
echo "Schedule is not available.";
}
mysql_free_result($result);
?>
I have this same code working in another place and when I run the query in phpMyAdmin it returns 5 rows. But, when I run this on the website it always says "Schedule is not available."
Any help would be greatly appreciated. Thanks!
You did not close off the error check:
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
} // <-- This is missing
if(mysql_num_rows($result)>0) {
Therefore the else of "Schedule not available" is the else to if(!result) {. In other words, if the query was successful it is going to print "Schedule not available"
Aren't you just missing a } here?
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit; // <-- expected `}` here
if(mysql_num_rows($result)>0) {
You should really improve your code style. Use a proper IDE.