Hye guys,
I am trying to get both "name" and "price" value for this Array in the same line but there is something not working.
This is the code in the front end.
<?php echo implode(array_column($post->booking_extra, 'name'), '<br />'); ?>
I tried
<?php echo implode(array_column($post->booking_extra, 'name'), ($post->booking_extra, 'price'), '<br />'); ?>
Got no results, also tried
<?php echo implode(array_column($post->booking_extra, 'name', 'price'), '<br />'); ?>
and
<?php echo implode(array_column($post->booking_extra, 'price'), '<br />'); ?>
In the line below, but obviously that just echos out the price in another line below. This must be some stupid error I'm making.
I described what i tried above.
Related
This is the problem that i am facing.
$value1=100;
$value2=5;
if i multiply the value like this, with a br tag at the end,
echo $value1*=$value2."</br>";
br tag is not working at all.
Can anyone help?.
Thanks in Advance
You could do :
echo ($value1*=$value2) . "<br/>";
I think it should be <br /> instead of </br>
Also, show the 'br' with another echo
echo $value1*=$value2;
echo "<br />".'should appear at new line';
<?php
$value1=100;
$value2=5;
$value1*=$value2;
echo $value1 . '<br />';
?>
Try
<?php
$value1=100;
$value2=5;
echo $value1*=$value2;
echo '<br/>';
echo 'test me'; // to check BR tag is working or not
?>
For php7:
echo "Message" . "\n";
Very simple but this echo isn't returning anything. I want to concatenate 2 values from an included PHP array file so I don't have to write the code twice. What am I writing incorrectly?
<?php echo $lang['work' . 'title']; ?>
Among others I have tried
<?php echo $lang['work', 'title']; ?>
<?php echo $lang['work' 'title']; ?>
<?php echo $lang['work'], $lang['title']; ?>
Check out php array documentation.
I am using this code to display (on the frontend) all assigned attributes of a product in Magento:
<?php if ($_product->getData('metal')): ?>
<?php echo nl2br($_product->getResource()->getAttribute('metal')->getFrontend()->getValue($_product )) ?>
<?php endif; ?>
I need to separate each item with a bullet point and a break <br/>. How would I edit this code to reflect those changes?
Thanks in advance.
_Sam
If you want more control over the output (maybe you want to style the individual value), use explode();
<?php $attr = explode("," , $_helper->productAttribute($_product, $_data['value'], $_data['code']));
echo "<ul>";
?>
<?php foreach ($attr as $attrValue) {
echo "<li>" . $attrValue . "</li>";
}
echo "</ul>";
?>
Assuming that the above code is "working"... make this change:
<?php echo "".nl2br($_product->getResource()->getAttribute('metal')->getFrontend()->getValue($_product ))."<br/>" ?>
the . is a string concatenation operator.
Or are you asking how to do it if the above is the HTML of a listing of products? Then this should work...
<?php
$somehtml=nl2br($_product->getResource()->getAttribute('metal')->getFrontend()->getValue($_product ));
$somehtml=explode("<br />",$somehtml); // This ASSumes nl2br inserts <br /> between each line and this
// would lead to the behaviour you want.
// see: http://php.net/manual/en/function.nl2br.php
$somehtml=implode("<br/>\n",$somehtml);
$somehtml="".$somehtml."<br/>\n";
echo $somehtml;
unset($somehtml);
?>
explode makes an array from a string by chopping up the string via the "<br />". implode then rejoins the the string by putting <br/>\n between each element. And finally, I add the bullet point to the front and br at the end. When imploding, you still must consider the "outside" of the string.
Solved.
It is easy: copy attributes.phtml from base if you do not have one in you default package.
Put in app/design/frontend/default/default/template/catalog/product/view/ folder
Change line 46 from:
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
to show separate product attributes:
<td class="data"><?php echo $_helper->productAttribute($_product, str_replace(",", "<br />", $_data['value']), $_data['code']) ?></td>
I have the following code:
<?php if(the_field('required_libraries') ) { echo 'Title' . $required_libraries; } ?>
The field does exist and it displays correctly. However, the 'Title' text does not.
This works for me where there aren't any variables, so I don't quite understand why it isn't working here.
I'm not sure I understand your question. You might need to use isset in your if statement.
<?php
if (isset($required_libraries)) {
echo 'Title' . $required_libraries;
}
?>
Can you post what your "the_field" function does?
Update
Per the documentation you provided, it looks like you should use get_field() in the if statement (not the_field()).
<?php
if(get_field('required_libraries')) {
echo 'Title ' . get_field('required_libraries');
}
?>
It looks like the_field() echos the field value, so you could also do this:
<?php
if(get_field('required_libraries')) {
echo 'Title ';
the_field('required_libraries');
}
?>
I have the 2 following echos :
<?php echo $data->county; ?>
This one gives me datas like "florida", "california"... from the database
and
<?php echo lang(california); ?>
This one gives me a translation from a lang.php file, for example :
'california' => 'La californie'
I would like to place the $data->county in the lang echo, I tried the following with no success :
<?php echo lang(.$data->county.); ?>
What's the error ? Is it possible to echo in an echo ?
What made you think you needed the dots? Just pass it like any other argument:
<?php echo lang($data->county); ?>
<?php echo lang($data->county); ?>
Lose the .s, they're for concatenating strings. You're just passing a string variable.