If column value = NO don't display - php

I have an if statement
<p>Included Services</p>
<?php foreach($services as $service): ?>
<?php if(!empty($service['service_webdesign'])){ ?>
<div><strong>web Design:</strong> <?php echo $service['service_webdesign'] ?></div>
<?php } ?>
<?php endforeach ?>
<p>Services charged by the hour</p>
<?php foreach($services as $service): ?>
<?php if(!empty($service['service_webdesign'])){ ?>
<div><strong>Service:</strong> <?php echo $service['service_webdesign'] ?></div>
<?php } ?>
<?php endforeach ?>
There are three possible values Yes, hourly rate or no.
In the first block I want to be able to echo the service column values
<div><strong>Service:</strong> <?php echo $service['service_webdesign'] ?></div>
only if the database value is 'yes'.
In the second block I want to echo the service fee column
<div><strong>Web Design:</strong> <?php echo $service['service_fee_webdesign'] ?>
</div>
only if the value of the 'service_webdesign' is set to 'hourly rate' but I do not actually want to show the value of 'service_webdesign' ('hourly rate').
An example of my database table structure is as follows
service_webdesign = Yes
service_fee_webdesign = NULL
service_graphicdesign = Hourly
service_fee_graphicdesign = 20
How can I achieve that within an if statement? Or would I need to create another SQL query for each of the blocks?

Related

how to do multiplication in php and mysql

I need to multiply the price by the quantity to get the total cost but i am not sure how to do this.
This is what i have done so far:
<?php do { ?>
<p align="Center">
<?php echo $row3['unitprice'] ?>
<?php echo $row3['quantity']; ?>
</p>
<?php } while ($row3 = mysqli_fetch_assoc($resultCustomer3))?>
at the moment i am only printing out unit price and the quantity.
how would i multiply the two to get the total?
HELP please!!
Try this
<?php while ($row3 = mysqli_fetch_assoc($resultCustomer3)) {?>
<p align="Center">
<?php echo $row3['unitprice']; ?>
<?php echo $row3['quantity']; ?>
<?php echo $row3['quantity']*$row3['unitprice']; ?>
</p>
<?php } ?>
To multiply two fields in php, you need this code:
$total = $mnth_190 * $rate_190;
After having calculated the result, you can normally output the variable total!

How to show invoice no and date in Magento?

I am using a page to display order details and want to show invoice no and date in that page. Please tell me how to show invoice no. Here is the code:
<div class="col-sm-4 invoice-`co`l">
<b>Order No. </b>#
<?php if ($this->getNoUseOrderLink()): ?>
<?php echo $_order->getRealOrderId(); ?>
<?php else: ?>
<?php echo $_order->getRealOrderId(); ?>
<?php endif; ?>
<br>
<b>Amount:</b> <?php echo "&nbsp".$this->gettotalamount(); ?><br>
<b>Payment Type:</b> <?php echo $_order->getPayment()->getMethodInstance()->getTitle(); ?>
Below is the code snippet to get Invoice info associated with any order. Based on your code, you have already loaded order model on $_order, so try below code.
<?php
// ignore below two lines if you already have order model
// $_order=Mage::getModel('sales/order')->loadByIncrementId($anyorderincrementid);
// $_order=Mage::getModel('sales/order')->load($anyorderentityid);
if ($_order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($_order->getInvoiceCollection() as $inv) {
echo "Invoice Id- ".$inv->getIncrementId();
echo "Invoice Date- ".date('d-m-Y',strtotime($inv->getCreatedAt()));
}
}
?>
To get date in d-m-y format (answer of your question which is in comments)
<?php
// format admin and store date
$orderAdminDate=date('d-m-y',strtotime($orderAdminDate));
$orderStoreDate=date('d-m-y',strtotime($orderStoreDate));
echo $orderAdminDate;
if ($orderAdminDate != $orderStoreDate):
echo date('d-m-y',strtotime($_order->getCreatedAtStoreDate()));
echo $orderStoreDate;
endif;
?>

PHP echo as condition inside PHP if statement

I would like to use a PHP echo as a condition inside a PHP if statement.
The aim is to have the list of blog articles written by John Doe, displayed on his biography page.
It worked when I directly wrote the author's name in the if condition:
<!-- current page: biography page -->
<div id="list_of_articles_by_John_Doe">
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == 'John Doe'): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
But I would like to automate the process, for each writer's biography page to have their own list of articles.
I tried to have as a condition the author of the current biography page ($page):
<!-- current page: biography page -->
<div id="automatic_list_of_articles">
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == $page->author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
but it makes another issue: it does not work because inside the foreach statement, $page->author() (condition in the if statement) does not echo the author once, but one time for each page('magazine')->children() as $article.
The condition if($article->author() == $page->author()) does not work in this case, as $page->author() is not strictly the writer's name.
I'm wondering how to call $page->author() to echo the writer's name only once, when inside the foreach statement.
What could be an option is to save all author within an array
// if article->author() isn't within the array
$authors[] == $article->author();
After that you could go as the following:
<?php foreach($authors as $author){ ?>
<?php foreach(page('magazine')->children() as $article): ?>
<?php if($article->author() == $author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
<?php } ?>
That should work, even if you must do 2 foreachs
<?php if( $article->author() == $page->author() ) { ?>
<p><?php echo $article->title(); ?></p>
<?php } ?>
should work, but you can also try
<?php
if( $article->author() == $page->author() ) {
echo "\n<p>", $article->title(), "</p>\n";
}
?>
which to me looks "cleaner"; but you'd have to have a look for missing whitespaces
I suggest trying to set it equal too a variable and then using that variable in the if statement.
<?php foreach(page('magazine')->children() as $article): ?>
<?php $condition = $page->author()?>
<?php if($article->author() == $condition ?>'): ?>
echo "\n<p>", $article->title(), "</p>\n";
<?php endif ?>
<?php endforeach ?>
I am not sure if my syntax is correct but i think it is something along them lines.
You cannot use echo in condition because it is special language construct that sends given contents to the output stream and it returns no value.
Are you sure you shouldn't have this?
<div id="automatic_list_of_articles">
<?php $page = page('magazine'); ?>
<?php foreach($page->children() as $article): ?>
<?php if($article->author() == $page->author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
I have reconstructed an approximation of what looks to be your data, and you can see it working at the link below. It correctly echo's multiple article titles.
Working example:
http://ideone.com/jvLVhF
In this example you can see the PHP as above works correctly, and it is likely a data issue (ie. you should perhaps be using $page and not calling a function in the foreach statement).

Magento static Blocks is not displaying properly.

I have created few static blocks just based on the category Id trying to display different blocks .
The problem being some times the block is displayed while some other times it is not .
I guess there is prob with code ? or the way magneto displays static blocks not sure ?
CODE:
<?php
<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==14): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==15): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==16): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==18): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==19): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==86): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==25): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==13): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==98): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_fbyz')->toHtml();?>
<?php else: ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_others')->toHtml();?>
<?php endif; ?>
</div>
<?php endif; ?>
please resolve my problem.
If you put this code in product view page then it it not properly way to get current category in product page..
Used Mage::registry("current_category") instead of Mage::getModel('catalog/layer')->getCurrentCategory();
If you come to category directly then you can get current category id product page.then you used to fetch current product categories ids.
$categoryIds = Mage::registry('current_product')->getCategoryIds();
if(Mage::registry("current_category"))
{
$category = Mage::getModel('catalog/category')
->load(Mage::registry("current_category")->getId());
}elseif(is_array($categoryIds )){
//multiple categories id of product. that way i was taken on list category
$category = Mage::getModel('catalog/category')->load($categoryIds[0]);
}
elseif(!is_null($categoryIds)){
$category = Mage::getModel('catalog/category')->load($categoryIds);
}
else{
//no categoies
}

Help with a foreach loop

In my website I am trying to display all the applicants to jobs that a user has posted, basically I want the out put to simimlar too,
Job Title 1
Aplicant Name 1
Aplicant Name 2
Applicant Name 3
Job Title 2
Applicant Name 4
Application Name 5
Basically I want the applications to be gathered under the jobs they applied for, however the out put I am current getting is,
Job Title 1
Application Name 1
Job Title 1
Applicant Name 2
The code I am using to do this foreach loop is as follows
<?php foreach($applications as $a) : ?>
<h3><?php echo $a['jobtitle']; ?></h3>
<li>
<img src="/media/uploads/candidates/<?php echo preg_replace('/(.gif|.jpg|.png)/', '_thumb$1', $a['profile_image']);?>" width="90" height="60"/>
<p><?php echo $a['name']; ?></p>
</li>
<?php endforeach; ?>
We need the data structure to properly answer, but I'm assuming you need a nested foreach...
<? foreach($jobs as $j): ?>
# list jobs
<? foreach($applicants as $a): ?>
<? if ($j['jobtitle'] == $a['jobtitle']): ?>
# list applicants
<? endif; ?>
<? endforeach; ?>
<? endforeach; ?>
Well you are getting that because you are only outputting
$a['jobtitle']
and
$a['name']
Where are the other names stored? Something like this is probably what you want, although that won't work if you copy/paste it as it seems that $applications[x]['name'] is not an array:
<?php foreach($applications as $a) : ?>
<h3><?php echo $a['jobtitle']; ?></h3>
<li>
<img src="/media/uploads/candidates/<?php echo preg_replace('/(.gif|.jpg|.png)/', '_thumb$1', $a['profile_image']);?>" width="90" height="60"/>
<?php foreach($a['name'] as $name)?>
<p><?php echo $name; ?></p>
<?php endforeach; ?>
</li>
<?php endforeach; ?>
I recommend pulling jobtitle and applicants from the database and storing them in a multidimensional array.
$jobs[$jobtitle][] = $applicant_name;
Then looping through this array in your view. I've omitted your image code for clarity.
foreach($jobs as $title=>applicants){
echo $title;
foreach($applicants as $name){
echo $name;
}
}

Categories