Hide the edit link when id is null - php

After foreach when p_id is null then show edit link for that particular row otherwise hide edit link
this is code i have tried with isset function but it hide edit for all row not the particular row
<?php foreach($listing as $value): ?>
<tr>
<td> <?php echo $value['name'] ?> </td>
<?php if(!isset($value["p_id"]) && empty($value["p_id"])) { ?>
<td> Edit</td>
<?php } ?>
<td>Delete</td>
</tr>
<?php endforeach ?>

in above statment use OR instead of &&. because this condition wont come true ever.

Use only this:
if($value["p_id"] != '')
{
echo //;
}

Related

Not working !==NULL

In my app I have a table in where I'd like lo highlight some rows if a date field is empty, here's my code:
<table>
<?php foreach ($conts as $cont): ?>
<tr <?php if ($cont['Cont']['shdate']!==NULL) echo 'class="bg-success"'; ?>>
</tr>
<?php endforeach; ?>
</table>
It does not work although I've checked in the database and the field is NULL, why could this be happening?

changing attributes of product view in magento

I have a section of extra information for the product. In the config you can add a link. This is showing the text of the link, but we want to have a word as a link and not the url to be seen.
For the product additional information there is now 1 working link. (a word that is the link instead of showing the url)
Now for a second field (second link), I want to do the same. When this field is filled with an url, the word "second link" must be the link, but not showing the url. The word "second link" is the link
I tried to change the attributes.phtml but I get lost changing the php code.
<?php foreach ($_additional as $_data): ?>
<tr class="<?php if ($_data['value'] == "No" or $_data['value']== "Nee" or $_data['value'] == "N/A" or $_data['value'] == "Nvt" ){?>no-data-value<?php } ?>">
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data">
<?php if($_data['code'] == 'link'){?>
<?php echo $this->__('Product page manufacturer')?>
<?php }else{?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php }?>
</td>
</tr>
<?php endforeach; ?>
I am trying to do the same for the second field. How do I change this in the php? I tried several things but ends up in a loop showing it twice or i get an error in the syntax.
You may try the code below:
<?php
$links = array('link' => 'Product page manufacturer',
'YOUR_CODE_OF_SECOND_LINK' => 'TEXT_FOR_SECOND_LINK');
foreach ($_additional as $_data): ?>
<tr class="<?php if ($_data['value'] == "No" or $_data['value']== "Nee" or $_data['value'] == "N/A" or $_data['value'] == "Nvt" ){?>no-data-value<?php } ?>">
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data">
<?php if(array_key_exists($_data['code'], $links)){
$code = $_data['code']; ?>
<?php echo $this->__($links[$code])?>
<?php }else{?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php }?>
</td>
</tr>
<?php endforeach; ?>
You will be able to add links' codes and texts to the $links array. It's not very good to edit template files by this way, but it should work.

Give two links in one HTML <td> tag

Here is one <td> tag that has the link to go to marks/details/index/someId,
<td>
<a href="<?php
echo $this->url('marks/details',array('action'=>'index','id'=>$item['studentAcademicId']))
?>">
<?php
if(($item['marksObtained'])!= Null )
{
echo $item['marksObtained'];
}
else {echo 'Add Marks'; };
?>
</td>
I want to add another link, in this same <td> after else {echo 'Add Marks'; } which would go to another link e.g Marks/details/addfromsession/someId
anchor tag is not closed after this you can add anchor. like as below
<td>
<a href="
<?php echo $this->url(
'marks/details',array('action'=>'index','id'=>$item['studentAcademicId']))?>">
<?php if(($item['marksObtained'])!= Null )
{ echo
$item['marksObtained'];}
else {echo 'Add Marks'; };?> </a>
SOME TEXT
</td>
This is the correct way to pass two links in one HTML <td> tag.
<?php foreach ($this->data as $item): ?>
<tr>
<td>
<?php if(isset( $item['marksObtained']) && $item['marksObtained'] > 0){?>
<a href="<?=$this->url( 'marks/details', array('action'=>'index', 'id'=>$item['studentAcademicId']))?>">
<?php echo $item['marksObtained']; ?></a>
<?php }else{ ?>
<a href="<?=$this->url( 'marks/details', array('action'=>'add', 'id'=>$item['studentAcademicId']))?>">
Add Marks</a>
<?php }?>
</td>
</tr>
<?php endforeach;?>
If condition is true, one link is passed, else the other link is passed, So now we have two tags that are working exactly to the question.

Clicking view button and nothing happens

After clicking the VIEW button and nothing happening, I started to wonder what's wrong?
GALLERIES NAME POST EDIT DELETE
Slideshow VIEW
SERVICES POST VIEW
Code:
<?php foreach ($gallery as $gallery_item): ?>
<tr>
<td><?php echo $gallery_item['galleries_name']; ?></td>
<td>
<?php if( $gallery_item['galleries_post_type'] == 'post') { echo "#"; }?>
</td>
<td>
<button type="button" class="edit" onclick="location.href = '
<?php
if( $gallery_item['galleries_post_type'] == 'post') {
echo site_url('cpages/galleries/'.$gallery_item['galleries_id']);
} else {
echo site_url('cpages/viewpictures/'.$gallery_item['galleries_id']);
}
?>
';">VIEW</button>
</td>
I think you should use links and describe them as button (role, type, whatsoever) and decore them with CSS. That is:
<?php
$id = $gallery_item['galleries_id']);
?>
<td>
<?php if ($gallery_item['galleries_post_type'] === 'post'): ?>
<a href="<?= site_url('cpages/galleries/'.$id); ?>" class="edit">
<?php elseif (): ?>
<a href="<?= site_url('cpages/viewpictures/'.$id); ?>" class="edit">
<?php endif; ?>
</td>
By searching for a better solution, I found an answer from BalusC that, I think, should solve your problem and help you understand how/what/when questions about buttons, links and so one.

OpenCart - Show a single attribute instead of all

I need to show a single attribute out of many attributes on product page. For example, I have author, publisher and format attributes for a product; and want to show only author in product page. Following code is showing all attributes in tabular format:
<?php foreach ($attribute_groups as $attribute_group) { ?>
<tbody>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<div>
<?php echo "<strong>",$attribute['name'], ":\n</strong>"; ?>
<?php echo $attribute['text']; ?>
</div>
<?php } ?>
A Better way to show single attribute for a product is to go to your product edit panel and remove all the attributes except the one you want to show
If you still want to do it in code which is not recommended then you can use and if your desired attribute
<?php foreach ($attribute_group['attribute'] as $attribute) {
if($attribute['name']=="Clockspeed") {
/* your attribute name for e.g i have used Clockspeed */
?>
<tr>
<td><?php echo $attribute['name']; ?></td>
<td><?php echo $attribute['text']; ?></td>
</tr>
<?php } } ?>

Categories