Echo out values in foreach loop [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have this code:
if(!empty($item['criteria'])){
foreach ($item['criteria'] as $item2){
echo "$item2[description]<br/>".PHP_EOL;
}
}
}
Now i need to modify this code to swing open the $item2[description]. I tried it like that:
if(!empty($item['criteria'])){
foreach ($item['criteria'] as $item2){
echo ''Click
<div id="', $item2['id'], '" style="display: none">', $item2['description'], '</div>';
}
}
}
I think there is a mistake in some signs.

if(!empty($item['criteria'])){
foreach ($item['criteria'] as $item2){
echo 'Click';
echo '<div id="'. $item2['id'].'" style="display: none">'. $item2['description'].'</div>';
}
}
}
you have some syntactical mistakes check this once

Use the . to concat strings
if(!empty($item['criteria'])){
foreach ($item['criteria'] as $item2){
echo 'Click'.
'<div id="'.$item2['id'].'" style="display: none">'.$item2['description'].'</div>';
}
}

Related

php processing string and echoing it out in a ul [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
so i have got this string:
<?php
$elements = "first, second, third, fourth, fifth";
?>
And i'd like it to be echoed out like this:
<ul>
<li>first</li>
<li>second</li>
<li>third</li>
<li>fourth</li>
<li>fifth</li>
</ul>
Try this, it may help you issue;
<?php
$elements = "first, second, third, fourth, fifth";
$numbers = explode(", ", $elements);
echo "<ul>";
foreach ($numbers as $number) {
echo "<li>{$number}</li>";
}
echo "</ul>";
?>
$elements = "first, second, third, fourth, fifth";
$arrayval=explode(',',$elements);
print_r($array);?>
<ul><?php
foreach($arrayval as $value){ ?>
<li><?php echo $value; ?></li>
<?php } ?>
</ul>

Using foreach loop to create links from an array [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Please help me create links using a php foreach loop that iterates over an array which contains the names of navbar links for a webpage.
Currently my loop creates links but when you click on them an error 404 page and displays in the url (for example when clicking on "blog"):
...homebrew-actual/blog.php>Blog <a></li><li><a href="
I would like the url to go to:
... homebrew-actual/blog.php
without the html tags.
Here is my current PHP loop:
<nav>
<ul>
<?php
$navOptions = array('index', 'showcase','about','blog','contact','forums');
foreach($navOptions AS $navOption) {
if ($navOption == $currentPage) {
print '<li>' . '' . ucfirst($navOption) . '</li>';
} else {
echo '<li>' . '<a href="/homebrew-actual/' . $navOption . '.php>' . ucfirst($navOption) . '</a></li>';
}
}
?>
<li class="special">Shop</li>
</ul>
</nav>
Please help me identify a solution to create a links for a navbar using an array with the link names and use a for loop to link to those pages.
Thank you for checking out this question.
You forgot a ":
print '<li>' . '' . ucfirst($navOption) . '</li>';
^--start href ^---end of href, missing "
Since you never close the href string, you end up with broken HTML.

Jquery syntax error Unexpected token < [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I get the following error and don't know where my mistake is:
Unexpected token <
Code (echo because of PHP used):
echo '<script type="text/javascript">
$(document).ready(function(){$("#sellerDrafts > tbody:last").append(';
foreach($this->view->sellercentral as $key2 => $value2)
{
echo '<tr><td><a href='. $value2->itemToken .'>Edit</a></td></tr>';}
echo '});</script>';
The problem is that you do not have quotes "" surrounding your append (and href), and it is not being closed with );.
echo '<script type="text/javascript">
$(document).ready(function(){$("#sellerDrafts > tbody:last").append("';
foreach($this->view->sellercentral as $key2 => $value2)
{
echo '<tr><td>Edit</td></tr>';
}
echo '");});</script>';
On a side note, this is really not the best way to do this. A better way to do this would be to build it in PHP first then hand it off to your javascript. Like so:
<?php
$table = "";
foreach($this->view->sellercentral as $key2 => $value2)
{
$table = '<tr><td>Edit</td></tr>';
}
?>
<script type="text/javascript">
$(document).ready(function(){
$("#sellerDrafts > tbody:last").append("<?php echo $table; ?>");
});
</script>

Css In Php not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
So this is the part of my code that I'm trying to make it work :
while ($row = mysql_fetch_array($satt)){
echo "<li";
if($row["satake"] == $fns ) {
echo "class=\"selected\"";
}
echo "><a href=\"home.php?fn=".urlencode($row["satake"]).
"\">{$row["satake"]}</a></li>";
}
And upper in page I have defined these:
<?php
if (isset($_GET['fn'])){
$fns = $_GET['fn'];
$ys = "";
} elseif (isset($_GET['yosef'])){
$ys = $_GET['yosef'];
$fns = "";
} else
{
$ys = "";
$fns = "";
}
?>
And this is the css :
.selected { font-weight: bold; }
It doesn't give me any error and it runs smoothly but doesn't work.
While it is true that you were missing an space, you might want to take these steps in the future to avoid this confussion:
PHP is a template engine. Use it as such (put PHP presentation INSIDE html, and not the other way around).
Check out the dynamic generated solution with the browser inspector (Chrome or Firefox).
So, your code becomes much more readable and easier to spot errors when you do:
while ($row = mysql_fetch_array($satt)){
// Some light logic
$satake = $row["satake"];
$liclass = $satake == $fns ? "selected" : "";
$cleansatake = urlencode($satake);
// The presentation
?>
<li class="<?= $liclass; ?>" >
<a href="home.php?fn=<?= $cleansatake; ?>" >
<?= $satake; ?>
</a>
</li>
<?php
} ?>

php echo div class not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am trying to echo a div class <div class="Box"> but not working. Can anyone help? Thanks.
echo '<div class="Box">
echo Anchor(T('Edit My Account'), '/profile/edit', FALSE, array('class' => 'Popup EditAccountLink'));
echo "<br />";
echo Anchor(T('Change My Password'), '/profile/password', FALSE, array('class' => 'Popup PasswordLink'));
echo "<br />";
$Inbox = 'Inbox';
$CountUnreadConversations = $Session->User->CountUnreadConversations;
if (is_numeric($CountUnreadConversations) && $CountUnreadConversations > 0)
$Inbox .= ''.$CountUnreadConversations.'';
echo Anchor(T('Inbox'), '/messages/all', 'Inbox');
</div>'
Your first and last lines are wrong, missing proper quotation marks and also an echo on the last line. It should be:
echo '<div class="Box">';
.... rest of code here...
echo '</div>';
You haven't terminated the string with ';.
echo '<div class="Box">';
Enable the error_reporting to E_ALL. Read on documentation. After this, you know what is happen.
This is a parse error. Enable error_reporting to E_ALL.

Categories