Infinite loop. Why? [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
i wanna test if my variable is empty or not to display some differents things.
When i don't use the else...if everything work but when i use this code :
<?php
$Amazon = get_post_meta($post->ID, "Lien Amazon", true);
?>
<?php
if( $Amazon != NULL ){
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;}
else {
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;}
?>
What is the problem ? Thank you

Here is an output error. You haven't closed and reopened the string on trying to concat a variable.
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;
Do instead:
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;

Related

echoing javascript not displaying any data [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am confused as to why this piece of simple code is not displaying any data in either console.log or .actions class. There are no errors in console and I can see the correct value being returned in the payload window in inspector.
I would be grateful if someone could point out my error. Many thanks
<?php
$value = '10';
echo '<script>';
echo 'var value = ' . json_encode($value) . ';';
echo '$(".actions").text(value);';
echo 'console.log(value);';
echo '</script>';
?>
Make sure that jQuery is imported before your script, try this example.
<?php $value = '10';?>
<p class='actions'>Loading...</p>
<script src="jquery.min.js"></script>
<noscript>Javascript is disabled!</noscript>
<script>
$(function(){
var str = 'value = <?=$value?>';
$('.actions').text(str);
console.log(str);
});
</script>

Clean HTML and PHP For Loop Not Displaying Anything [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
<?php for($x = 0; $x <= count($slides); $x++):?>
<li data-target="#main-carousel" data-slide-to="<?php echo($x);?>'" class="active"></li>
<?php endforeach; ?>
Not exactly sure what the error is everything seems right.
You start yourself with a for loop, while closing it with a foreach loop. These are two very different things and cannot be matched like that.
You simply need to replace
<?php endforeach; ?>
with
<?php endfor; ?>
Alternatively, you can use curlybrackets { instead, having something like
<?php for($x = 0; $x <= count($slides); $x++) { ?>
<!-- do HTML here -->
<?php } ?>

Else status in php [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I would need some help, since this code does not work (I have lack of knowledge, but I need to have it in that format)
$user_goals is array()
$user_count is just a number like 15
<?php foreach ($user_goals as $number): ?>
<?php if ($number < $user_count): ?>
<h5 class="text-center"><strike><?php echo htmlspecialchars($number); ?> users</strike></h5>
<?php else: ?>
<h5 class="text-center"><?php echo htmlspecialchars($number); ?> users</h5>
<?php endif; ?>
<?php endforeach; ?>
Any help will be apreciated :)
result that I want:
$user_count = 15;
$user_goals = array(
10,
15,
20,
etc,
);
so I want to get:
<strike>10</strike><br>
<strike>15</strike><br>
20
Solved it myself
<?php
foreach ($user_goals as $number) {
if ($number <= $users_count) {
echo "<h5 class='text-center'><strike>$number users</strike></h5>";
}else{
echo "<h5 class='text-center'>$number users</h5>";
}
}
?>
If you are looking to add a strike through when the goal is less than or equal to, you need to use that comparison operator.
if ($number <= $user_count)

if else with a link doesn't work [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
If $item not equal to false then echo first link, I then used onclick, but the problem is it seem it always goes to 2nd link. I inspected the $item, it's true, but how come it escaped the if scope? my markup as below:
<div>
<?php
if($item !== false){ ?>
<a onclick="window.open('<?php echo $item['2nd']; ?>');">
<?php }else{ ?>
<a href="<?php echo $item['url']; ?>">
<?php }?>
<div class="content">
</div>
</a>
</div>
You are using a strict "not equal" comparison, which you probably didn't mean to do.
From your code, it appears that $item is an array, but the line if ($item !== false) specifically checks if $item is a boolean false. If $item is an array, then the if statement will always return false because $item isn't a boolean.

Switch Statment Give Always The default [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 8 years ago.
Improve this question
I have a problem in my script in wampserver. It runs well. But in my hosting it doesn't display
the page which is named classed.php?cat=[category_Name_Example]
<?php header("Content-type: text/html; charset=utf-8");
?>
<?php include_once("analyticstracking.php") ?>
<?php
include 'includis/html_codes.php';
include 'includis/config.php';
$catID= mysql_real_escape_string($_GET['cat']);
switch ($catID)
{
case 'javascript' :
$catName = "javascript";
$PageTitle = "Javascript ";
$img = "img/javascript.png";
break;
case 'htmlandcss' :
$catName = "htmlandcss";
$PageTitle = "html ";
$img = "img/html2.png";
break;
default:header('location: /404');
}
if (!isset($catID)){
header ('Location 404.php');
}
if (empty($catID)){header ('Location 404.php');}
include 'includis/db.php';
?>
please help thanx :)
Most probable reason is that you do not have an open database connection while calling to this function. In this case mysql_real_escape_string just returns false.

Categories