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?
Related
For a web dev projet for my school, I've to program a Trello-like. I've to display board, with different columns but I really don't know how to generate one column per element in my foreach loop.
If someone could help me I'd be thanksfull!
Here's the foreach loop:
<?php foreach ($currentColumns as $currentColumn): ?>
(<?= $currentColumn['title']?> ) <?= $currentColumn['position'] ?>
<?php endforeach; ?>
here, you can do like this..
<table>
<tr>
<?php foreach ($currentColumns as $currentColumn): ?>
<td>
(<?= $currentColumn['title']?> ) <?= $currentColumn['position'] ?>
</td>
<?php endforeach; ?>
</tr>
</table>
I have a Loop which is outputting data into a html form and table. How can I limit the number of columns it displays, the reason i wanna do this is because i have limited space and the loop might run for 1000 times or even more depending on the user.
I want to Limit the Columns to say 6, so if the loop runs 6 times I want it to create a new row for another 6 columns and repeat again.
<form method="POST" action="script.php">
<table><tr>
<td><input type="checkbox" name="itemSelect[]" class="itemSelect" value="<?php echo $id; ?>" /></td>
<td>
<div class="item-box" data-id="<?php echo $id; ?>">
<img src="<?php echo $value['image_inventory']; ?>.png">
<div id="rarity">
<p> <?php
if (!isset($value['item_rarity'])) {
$rarity = "common";
echo $rarity;
} else {
$rarity = $value['item_rarity'];
echo $rarity;
}
?> </p>
</div>
</div></td>
</tr> </table>
<?php
}
}
?>
</table>
<button type="Submit">
Send Trade Offer
</button>
this should help, adjust the columns as needed:
<?php
$data = array_fill(0,100,"text");
$i = 0;
$columns = 8;
$rest = $columns-(count($data)%$columns);
?>
<table>
<tr>
<?php foreach($data as $cell): ?>
<?php if(!($i%$columns)) echo '</tr><tr>'?>
<td><?= $cell ?></td>
<?php $i++;?>
<?php endforeach;?>
<!-- fill rest cells-->
<?php if($rest<$columns):for($r=0;$r<$rest;$r++): ?>
<td>fill</td>
<?php endfor;endif; ?>
</tr>
</table>
P.S- could be a better Idea to not use a table at all and just float each "cell" left (use a div element for example) that way the layout would be responsive
Is it possible to configure PhpStorm 8 to indent HTML and PHP code separately?
I'll copy the examples from this question: How to properly indent PHP/HTML mixed code?
How PhpStorm formats the code currently:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
How I want it to look like:
<table>
<?php foreach ($rows as $row): ?>
<tr>
<?php if ($row->foo()): ?>
<?php echo $row ?>
<?php else: ?>
Something else
<?php endif ?>
</tr>
<?php endforeach ?>
</table>
No, not currently possible. See this comment
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 //;
}
I have created a product attribute called product_downloads, I can put a file name there and it appears in the product view page in the tab "Additional Information" with a link to the file name. I have successfully implemented this idea for one download, but for some products I will have multiple downloads...
Like I said, I have the code working with one download per product, all that took was a small amount of code inside of app/design/frontend/base/default/template/catalog/product/view/attributes.phtml
Where the original code was:
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
this is the code I have replaced that with:
<?php foreach ($_additional as $_data): ?>
<?php if ((string)$_data['value'] != '' and $_data['value'] != 'N/A'): ?> <!-- IF NOTHING DO NOTHING-->
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<?php if ($_data['code'] == 'product_download'): ?>
<td>
Product PDF
</td>
<?php else: ?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php endif; ?>
</tr>
<?php endif; ?>
<?php endforeach; ?>
This works perfectly, however... What I need now is to look at the value of product_download, if it has a comma(or some other divider, if this would interfere with a csv format) make two separate links to two seperate files..
One major thing to note... I rely heavily on MAGMI, which is why I have taken this route as no extension allows me to massively import attachments to products.
This is for spec sheets and such... some products have multiple spec sheets. I want to use a single attribute to store multiple file names and have code that will differentiate between the two.
you can use logic with explode function And change your if condition with my custom code as below
<?php if ($_data['code'] == 'product_download'): ?>
<?php
$product_downloads = explode(",",$_product->getProductDownload());
foreach($product_downloads as $download):
?>
<td>
Product PDF
</td>
<?php endforeach; ?>
<?php else: ?>
<?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?>
<?php endif; ?>
this is just logic you can use as per your thoughts as well.
hope this will sure help you.