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
} ?>
Related
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>';
}
}
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>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I need some little help on a simple thing!
I have this table in my database, where I have a number of images stored, called "covers".
And then I have a table in HTML that displays the covers of this MySQL table inside one of it's cells.
Like this:
<td><a href="movie.php?id=<?php echo $idt + 1; ?>">
<?php echo '<img src="'.htmlentities($idt + 1['cover'], ENT_QUOTES, 'UTF-8').'" alt="Cover" style="max-width:300px;max-height:300px;" />';; ?></a></td>
And this is the code before
$req = mysql_query("select id, name, year, genre, cover from movies");
$dnn = mysql_fetch_array($req);
$idt = $dnn['id'];
But why doesn't it work when I try to dynamically change id by putting this?
$idt + 1;
In order to output data from multiple rows, I suggest using a loop like this:
while ($row = mysql_fetch_assoc($req)) {
?><td>
<a href="movie.php?id=<?php echo $row['id']; ?>">
<img src="<?php echo htmlentities($row['cover'], ENT_QUOTES, 'UTF-8'); ?>" alt="Cover" />
</a>
</td><?php
}
You need to fetch a whole set of results and not just one id and increment it in the view. You should do a foreach loop on $idt like that:
foreach($dnn as $row){
$id=$row['id'];
$cover=$row['cover'];
$genre=$row['genre'];
//etc...
//now echo html with vars like this:
echo "<img src=\"$cover\"/>";
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am using php echo throughout different pages on a project, to update a percentage value that is changing daily. This value can be negative or positive.
Here is my code:
<i class="icon-thumbs-up"><strong> <?php $file = file('include.txt');echo $file[n]; ?></strong></i>
I am using FontAwesome icons with a Bootstrap template. Everything is working fine like this.
Now, if the percentage is negative, I would like to use class="icon-thumbs-down" instead of class="icon-thumbs-up".
I have tried to achieve this using
<i class="<?php $file = file('include.txt');echo $file[n]; ?>"><strong> <?php $file = file('include.txt');echo $file[13]; ?></strong></i>
in order to change it on all pages.
However, this is not working. Thanks for any hints!
To clarify:
<i class="icon-thumbs-up"><strong> <?php $file = file('include.txt');echo $file[0]; ?></strong></i>
Content of include.text: 0.58% on line 1 -> All working fine. I got the thumbs up displayed and next to it the value 0.58%.
Now I tried to change to:
<i class="<?php $file = file('include.txt');echo $file[1]; ?>"><strong> <?php $file = file('include.txt');echo $file[0]; ?></strong></i>
Content of include.text: 0.58% on line 1 and icon-thumbs-up on line 2. (Which I would like to change in the include.txt on a daily basis to icon-thumbs-up or icon-thumbs-down, depending on the value of line 1.)
If value from file('include.txt') is integer then you can use ternary operator to echo correct css class, eg. like this:
<li class="<?php echo (int) $file[0] < 0 ? 'icon-thumbs-down' : 'icon-thumbs-up'; ?>"></li>
This is a bit hard to reply to as your code isnt that clear. I can however hand you the following suggestion via an example:
$someInt = 10;
echo $someInt < 0 ? 'icon-negative' : 'icon-positive'; // will echo positive
$someInt = -3;
echo $someInt < 0 ? 'icon-negative' : 'icon-positive'; // will echo negative
This is a short if/else (ternary). To demonstrate how it works, this would be the same in a full syntax:
$someInt = -3;
if($someInt < 0){
echo 'icon-negative';
}
else{
echo 'icon-positive';
}
I would do the following:
<?php
// your logic here, move in another file if this gets bigger:
function percentage($nb) {
$file = file('include.txt');
return $file[$nb];
}
?>
<i class="<?php echo percentage(5) > 0 ? 'positive' : 'negative' ?>">
<strong>Text</strong>
</i>
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Hi I am web designer and I would like to know how to set menu subtitle? It is easily possible with yoo themes but I need to know how it is done without using YooTheme templates. I think there is need of little modification in mod_menu but I don't know what exactly. I googled all day and can't find a solution.
There are certainly better solutions but i've done it this way:
Insert a charakter in the name of your menu-item. For example a "|".
It should look like this: Title | Subtitle. At this position you can divide the name.
Now you have to override the file default_component.php in modules/mod_menu/tmpl.
Add this lines:
$parts = explode("|", $linktype);
// the "|" is the divider
if(isset($parts[1])){
$linktype = $parts[0].'<span>'.$parts[1].'</span>';
}else{
$linktype = $parts[0];
};
after:
$class = $item->anchor_css ? 'class="'.$item->anchor_css.'" ' : '';
$title = $item->anchor_title ? 'title="'.$item->anchor_title.'" ' : '';
if ($item->menu_image) {
$item->params->get('menu_text', 1 ) ?
$linktype = '<img src="'.$item->menu_image.'" alt="'.$item->title.'" /><span class="image-title">'.$item->title.'</span> ' :
$linktype = '<img src="'.$item->menu_image.'" alt="'.$item->title.'" />';
}
else { $linktype = $item->title;
}
Now you have a span around the subtitle and it's possible to style it.