I have a little issue with my foreach loop and can't find the mistake.
first array
$gemeinden = [$barsbek_G, $barsbek_U, $barsbek_F, $bendfeld_G, $bendfeld_U, $bendfeld_F, $brodersdorf_G, $brodersdorf_U, $brodersdorf_F, $fahren_G, $fahren_U, $fahren_F, $fiefbergen_G, $fiefbergen_U, $fiefbergen_F, $hoehndorf_G, $hoehndorf_U, $hoehndorf_F, $koehn_G, $koehn_U, $koehn_F, $krokau_G, $krokau_U, $krokau_F, $krummbek_G, $krummbek_U, $krummbek_F, $laboe_G, $laboe_U, $laboe_F, $lutterbek_G, $lutterbek_U, $lutterbek_F, $passade_G, $passade_U, $passade_F, $prasdorf_G, $prasdorf_U, $prasdorf_F, $probst_G, $probst_U, $probst_F, $schoenberg_G, $schoenberg_U, $schoenberg_F, $stakendorf_G, $stakendorf_U, $stakendorf_F, $stein_G, $stein_U, $stein_F, $stoltenberg_G, $stoltenberg_U, $stoltenberg_F, $wendtorf_G, $wendtorf_U, $wendtorf_F, $wisch_G, $wisch_U, $wisch_F];
second array
$results = $wpdb->get_results( $queryGemeinde );
That's my foreach loop
<?php foreach($results as $index => $print) { ?>
<tr> <!-- display data -->
<td width=<?php echo $width[0]; ?>><?php echo $print->postleitzahl; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $print->ort; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $gemeinden[$index]; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $gemeinden[$index]; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $gemeinden[$index]; ?></td>
</tr>
<?php }?>
</tbody>
</table>
That's the result
It seems as if it is stucked. And it makes sense but how Can I tell the foreach loop to go further after the third <td></td>
As per my understanding you need to fetch next item after 3rd td so you can use below approach:
<?php foreach($results as $index => $print) { ?>
<tr> <!-- display data -->
<td width=<?php echo $width[0]; ?>><?php echo $print->postleitzahl; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $print->ort; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $gemeinden[$index]; ?></td>
<?php $index++; ?>
<td width=<?php echo $width[1]; ?>><?php echo $gemeinden[$index]; ?></td>
<?php $index++; ?>
<td width=<?php echo $width[1]; ?>><?php echo $gemeinden[$index]; ?></td>
</tr>
<?php }?>
</tbody>
</table>
Or you can even iterate loop as below as well:
<?php foreach($results as $index => $print) { ?>
<tr> <!-- display data -->
<td width=<?php echo $width[0]; ?>><?php echo $print->postleitzahl; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $print->ort; ?></td>
<?php foreach($gemeinden as $gemValue) { ?>
<td width=<?php echo $width[1]; ?>><?php echo $gemValue; ?></td>
<?php } ?>
</tr>
<?php }?>
</tbody>
</table>
Hope it helps you!!
Related
What am I missing here? It always produces new tables instead of one table where all datasets are in.
foreach($results as $print) { ?>
<table class='wp-list-table widefat striped'>
<thead>
<tr> <!-- display table header -->
<th style='text-align:center;' width=<?php echo $width[0]; ?>><?php echo $character[0]; ?></th>
<th style='text-align:center;' width=<?php echo $width[1]; ?>><?php echo $character[1]; ?></th>
</tr>
</thead>
<tbody>
<form action='' method='post'>
<tr> <!-- display data -->
<td width=<?php echo $width[0]; ?>><?php echo $print->postleitzahl; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $print->ort; ?></td>
</tr>
</form>
<?php } ?>
</tbody>
</table>
Can you find my mistake? Sorry but I can't see it.
I would do it this way:
<table class='wp-list-table widefat striped'>
<thead>
<tr> <!-- display table header -->
<th style='text-align:center;' width=<?php echo $width[0]; ?>><?php echo $character[0]; ?></th>
<th style='text-align:center;' width=<?php echo $width[1]; ?>><?php echo $character[1]; ?></th>
</tr>
</thead>
<tbody>
foreach($results as $print) { ?>
<form action='' method='post'>
<tr> <!-- display data -->
<td width=<?php echo $width[0]; ?>><?php echo $print->postleitzahl; ?></td>
<td width=<?php echo $width[1]; ?>><?php echo $print->ort; ?></td>
</tr>
</form>
<?php } ?>
</tbody>
</table>
I have table rowspan dynamic on CodeIgniter app like this :
<table>
<tr>
<td>No</td>
<td>Data</td>
<td>Data 2</td>
<td>Qty</td>
<td>Price</td>
<td>Sub Total</td>
<td>TOtal</td>
</tr>
<?php
$source1 = $this->db->query("select * from table")->result_array();
$no=1;
foreach($source1 as source1){ ?>
<tr>
<?php
$source2 = $this->db->query("select * from table where data1='$source1[data1]'");
$total_source2 = $source2->num_rows();
$source3 = $source2->result_array();
?>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $no; ?></td>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $source1['data1']; ?></td>
<?php foreach($source3 as $source3){ ?>
<td><?php echo $source3['data2'] ?></td>
<td><?php echo $source3['qty'] ?></td>
<td><?php echo $source3['price'] ?></td>
<td><?php echo $source3['sub_total'] ?></td>
<td><?php echo $source3['total'] ?></td>
</tr>
<?php } ?>
<?php $no++; } ?>
</table>
This is result of my code:
How to make it like this
?
Thanks.
This is about as efficient as anything I can come up with without the actual SQL file and I'm not sure if it works:
<table>
<tr>
<td>No</td>
<td>Data</td>
<td>Data 2</td>
<td>Qty</td>
<td>Price</td>
<td>Sub Total</td>
<td>Total</td>
</tr>
<?php
$source1 = $this->db->query("select * from table")->result_array();
$no = 1;
foreach ($source1 as $source1) {
?>
<tr>
<?php
$source2 = $this->db->query('select * from table where data1 = ' . $source1['data1']);
$total_source2 = $source2->num_rows();
$source3 = $source2->result_array();
$rowspan = true;
?>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $no; ?></td>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $source1['data1']; ?></td>
<?php foreach ($source3 as $source3) { ?>
<td><?php echo $source3['data2'] ?></td>
<td><?php echo $source3['qty'] ?></td>
<td><?php echo $source3['price'] ?></td>
<td><?php echo $source3['sub_total'] ?></td>
<?php
if ($rowspan) {
$q = $this->db->query('SELECT SUM(`sub_total`) as `nb` FROM `table` WHERE `data1` = ' . $source1['data1']);
echo "<td rowspan='{$total_source2}'>" . $q->row()->nb . '</td>';
$rowspan = false;
}
?>
</tr>
<?php } ?>
<?php
$no++;
}
?>
</table>
i got two arrays.
from results i want to make a table with foreach
but i dont know how to make it work in one table row..
this is what i got
<table>
<?php foreach ($appky as $appka) : ?>
<tr class="counter_apps" height="20px" >
<td width="40%"><?php echo $appka->name; ?></td>
<td width="20%"><?php echo $appka->all_items;?></td>
<td width="20%"><?php echo $appka->published; ?></td>
<td width="20%"><?php echo $appka->unpublished; ?></td>
</tr>
<?php endforeach; ?>
</table>
<table>
<?php foreach ($applications as $application) : ?>
<tr><td><?php echo $application->name; ?></td></tr>
<?php endforeach; ?>
</table>
so what i want is simply add to the first table another column with $application->name;
what i'm missing here??
thanks
<table>
<?php
$count = count($appky);
for($i=0; $i< $count; $i++) { ?>
<tr class="counter_apps" height="20px" >
<td width="40%"><?php echo $appky[$i]->name; ?></td>
<td width="20%"><?php echo $appky[$i]->all_items;?></td>
<td width="20%"><?php echo $appky[$i]->published; ?></td>
<td width="20%"><?php echo $appky[$i]->unpublished; ?></td>
<td width="20%"><?php echo $applications[$i]->name; ?></td>
</tr>
<?php } ?>
</table>
use for instead of foreach
<table>
<?php for($i=0 ; $i<count($appky) ; $i++ ) { ?>
<tr class="counter_apps" height="20px" >
<td width="40%"><?php echo $appka[$i]->name; ?></td>
<td width="20%"><?php echo $appka[$i]->all_items;?></td>
<td width="20%"><?php echo $appka[$i]->published; ?></td>
<td width="20%"><?php echo $appka[$i]->unpublished; ?></td>
<td width="20%"><?php echo isset($applications[$i]) ? $applications[$i]->name : '' ; ?></td>
</tr>
<?php } ?>
</table>
Assuming your two arrays aren't necessarily in order - If you have some data that matches between your $appka and $application you can try something like this below:
<table>
<?php foreach ($appky as $appka) : ?>
<tr class="counter_apps" height="20px" >
<td width="40%"><?php echo $appka->name; ?></td>
<td width="20%"><?php echo $appka->all_items;?></td>
<td width="20%"><?php echo $appka->published; ?></td>
<td width="20%"><?php echo $appka->unpublished; ?></td>
<?php foreach ($applications as $application) : ?>
<?php if ($appka->id == $application->id) { ?>
<td><?php echo $application->name; ?></td>
<?php } ?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
Otherwise you wont be able to spit out the correct application name. The above solution uses an id field, but you probably hove something else you can match on.
We need to get Order ID, Order Value and Coupon Code from success.phtml.
We already have Google added to our success.phtml, and now we need to set up a new affiliate. We are not sure what $order_details and $adwords_saleamt do? Can we re-use them in any way?
Example
<?php
$order_details = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal;
?>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxxxxxx;
var google_conversion_language = "xy";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "xxxxxxxxxxxx";
var google_conversion_value = 0.00;
if (<?php echo $adwords_saleamt; ?>) {
google_conversion_value = <?php echo $adwords_saleamt; ?>;
}
var google_conversion_currency = "EUR";
var google_remarketing_only = false;
/* ]]> */
</script>
You can try following
$order_details = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal; //subtotal without tax and shipping
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); //Order Id
$couponCode = $order_details->coupon_code; //Coupon code
Then use the values in your affiliate code.
Code there please, copy and paste in your file and then check, if any issue let me know...
echo $this->getLayout()->createBlock('checkout/cart_totals')->setTemplate('onepagecheckout/onepage/review/totals.phtml')->toHtml();
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id);
// Get shipping method
$shipping_method = $order_details->_data["shipping_description"];
// Get ship-to address information
$shipping_address_data = $order_details->getShippingAddress();
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$card = $session->getGiftcard();
$cvv = $session->getGiftcardCvd();
$amount = $session->getGiftcardDeduct();
?>
<div class="inner_content">
<div class="inner-header-categories clearfix">
<h1><?php echo $this->__('Order Confirmation') ?></h1>
</div>
<div class="order_confirmation_div">
<h3><?php echo $this->__('Thank you for your order!') ?></h3>
<p>
<?php echo $this->__('Dear') ?> <?php echo $shipping_address_data['firstname']; ?>,<br>
<?php echo $this->__('Thank you for your order!') ?><br>
<?php if ($this->getCanViewOrder()) :?>
<p><?php echo $this->__('Your order id is: %s.', sprintf('%s', $this->escapeHtml($this->getViewOrderUrl()), $this->escapeHtml($this->getOrderId()))) ?></p>
<?php else :?>
<p><?php echo $this->__('Your order id is: %s.', $this->escapeHtml($this->getOrderId())) ?></p>
<?php endif;?>
</p>
<?php
$orderObj = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$orderItems = $orderObj->getAllItems();
?>
<h4><?php echo $this->__('Item Summary') ?></h4>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="order_ct_table">
<tr>
<th><?php echo $this->__('Product') ?></th>
<!--<th>Ship by</th>
<th>Delivers By</th>-->
<th><?php echo $this->__('Qty') ?></td>
<th class="no_border"><?php echo $this->__('UNIT PRICE') ?></th>
</tr>
<?php foreach($orderItems as $item)
{
?>
<tr>
<td class="porduct_dark_text"><div class="image_cart_in"><p><?php echo $item->getName();?></p></div></td>
<!--<td>18 August 2013</td>
<td>20 August 2013</td>-->
<td><?php echo round($item->getQtyOrdered(), 0);?></td>
<td class="no_border">$<?php echo number_format($item->getPrice(),2); ?></td>
</tr>
<?php }
?>
</table>
<h4><?php echo $this->__('Purchase Summary') ?>:</h4>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="order_ct_table_two">
<tr>
<td class="col_one_left"><?php echo $this->__('ITEM SUB TOTAL') ?> :</td>
<td class="no_border">$<?php echo number_format($orderValue = $orderObj->getSubtotal(),2);?></td>
</tr>
<?php if($orderObj->getDiscountAmount()!=0) { ?>
<tr>
<td class="col_one_left"><?php echo $this->__('Discount') ?> :</td>
<td class="no_border">$<?php echo number_format($orderValue = $orderObj->getDiscountAmount(),2);?></td>
</tr>
<?php } ?>
<tr>
<td class="col_one_left"><?php echo $orderObj->getShippingDescription(); ?>:</td>
<td class="no_border">$<?php echo number_format($orderSValue = $orderObj->getShippingAmount(),2); ?></td>
</tr>
<?php if(!empty($card)): ?>
<tr>
<td class="col_one_left"><?php echo $this->__('Giftcard ('.$card.') discount') ?>:</td>
<td class="no_border">$<?php echo number_format($amount,2); ?></td>
</tr>
<?php endif; ?>
<tr>
<td class="col_one_left"><?php echo $this->__('Tax') ?>:</td>
<?php
$GT = number_format($orderObj->getGrandTotal(),2);
$STA = number_format($orderSValue = $orderObj->getShippingAmount(),2);
$IST = number_format($orderValue = $orderObj->getSubtotal(),2);
$TAX = $IST+$STA;
$TTAX = $GT-$TAX;
?>
<td class="no_border">$<?php echo number_format($orderSValue = $orderObj->getTaxAmount(),2); ?></td>
</tr>
<tr>
<td class="col_one_left"><?php echo $this->__('Total') ?>:</td>
<td class="no_border">$<?php echo $GT;?></td>
</tr>
</table>
<ul class="billing_detail_confirm_ul_top"><li><h4><?php echo $this->__('Billing Address') ?></h4></li>
<li><h4><?php echo $this->__('Shipping Address') ?></h4></li></ul>
<ul class="billing_detail_confirm_ul">
<li>
<table border="0" cellspacing="0" cellpadding="0" style="border-right:none;">
<tr>
<td><?php echo $this->__('First Name') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['firstname']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Last Name') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['lastname'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Company') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['company'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Phone') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['telephone'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Address') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['street'];?><br>
<?php echo $shipping_address_data['region']; ?>, <?php echo $shipping_address_data['postcode']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('City') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['city'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Country') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['country_id'];?></td>
</tr>
<tr>
<td><?php echo $this->__('State') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['region']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Zip') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['postcode']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Email') ?></td>
<td class="right_bold_text"><?php if($shipping_address_data['email']=='') { echo Mage::getSingleton('customer/session')->getCustomer()->getEmail(); } else { echo $shipping_address_data['email']; } ?></td>
</tr>
</table>
</li>
<li>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php echo $this->__('First Name') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['firstname']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Last Name') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['lastname'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Company') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['company'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Phone') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['telephone'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Address') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['street'];?><br>
<?php echo $shipping_address_data['region']; ?>, <?php echo $shipping_address_data['postcode']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('City') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['city'];?></td>
</tr>
<tr>
<td><?php echo $this->__('Country') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['country_id'];?></td>
</tr>
<tr>
<td><?php echo $this->__('State') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['region']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Zip') ?></td>
<td class="right_bold_text"><?php echo $shipping_address_data['postcode']; ?></td>
</tr>
<tr>
<td><?php echo $this->__('Email') ?></td>
<td class="right_bold_text"><?php if($shipping_address_data['email']=='') { echo Mage::getSingleton('customer/session')->getCustomer()->getEmail(); } else { echo $shipping_address_data['email']; } ?></td>
</tr>
</table>
</li>
</ul>
<h3><td><?php echo $this->__('Thank you for shopping with us!') ?></td></h3>
<button class="proceed" style="margin-bottom:40px;" onclick="window.location='<?php echo $this->getUrl() ?>'"><?php echo $this->__('Return to Homepage') ?></button>
</div>
</div>
I am using a foreach loop to display table records. Below is my code for indexSuccess.php template
<?php $counter = 0; ?>
<?php foreach ($prescription->getPrescriptionDrugs() as $prescriptionDrug): ?>
<?php $counter++; ?>
<tr>
<th class="start"><?php echo $prescriptionDrug->getDrug()->getDrugName() ?></th>
<td><?php echo $prescriptionDrug->getAmountPerTime() ?></td>
<td><?php echo $prescriptionDrug->getTimesPerDay() ?></td>
<td><?php echo $prescriptionDrug->getCreater() ?> (<?php echo $prescriptionDrug->getCreatedAt() ?>)</td>
</tr>
<?php endforeach; ?>
<?php if($counter==0): ?>
<tr>
<td colspan="5">No items found</td>
</tr>
<?php endif; ?>
I can't seem to find a way to echo
<td colspan="5">No items found</td>
when the table is not showing any records.
If i use
<?php echo var_dump ($counter); ?>
It displays the result below
int 1
int 2
int 1
int 2
int 1
int 2
int 1
int 2
int 1
int 2
<?php if($prescription->getPrescriptionDrugs()->count() == 0): ?>
<tr>
<td colspan="5">No items found</td>
</tr>
<?php else: ?>
<?php foreach ($prescription->getPrescriptionDrugs() as $prescriptionDrug): ?>
<tr>
<th class="start"><?php echo $prescriptionDrug->getDrug()->getDrugName() ?></th>
<td><?php echo $prescriptionDrug->getAmountPerTime() ?></td>
<td><?php echo $prescriptionDrug->getTimesPerDay() ?></td>
<td><?php echo $prescriptionDrug->getCreater() ?> (<?php echo $prescriptionDrug->getCreatedAt() ?>)</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
You can use the count() function witch returns you the number of rows.
<?php $rows = count($prescription->getPrescriptionDrugs()); ?>
<?php if($rows==0){ ?>
<tr>
<td colspan="5">No items found</td>
</tr>
<?php } else { ?>
<?php foreach ($prescription->getPrescriptionDrugs() as $prescriptionDrug): ?>
<tr>
<th class="start"><?php echo $prescriptionDrug->getDrug()->getDrugName() ?></th>
<td><?php echo $prescriptionDrug->getAmountPerTime() ?></td>
<td><?php echo $prescriptionDrug->getTimesPerDay() ?></td>
<td><?php echo $prescriptionDrug->getCreater() ?> (<?php echo $prescriptionDrug->getCreatedAt() ?>)</td>
</tr>
<?php endforeach; ?>
<?php } ?>