Hello everybody i put this code but and when the value referal is < 0 running }else{ but i dont do.
if($referal > 0 && is_numeric($referal) && $site['refsys'] == 1 && $site['aff_click_req'] == 0){
//code
if($user['id'] > 0){
//code
}
}
}
I want to put }else{ but not how, }else{ $referal="$referal2"; ????
if($referal > 0 && is_numeric($referal) && $site['refsys'] == 1 && $site['aff_click_req'] == 0){
//code
if($user['id'] > 0){
//code
}
}}else{ $referal="$referal2";
}
Regards and thanks
First of all this the if elseif statement syntax.
if($condition1){
// code if the first condition is true
}elseif($condition2){
// code if the first condition is false and the second one is true
}else{
// code if both the first and second condition are false
}
it is described in the php official website
If I have understood your question you want, when the $referal1 is equal to 0, to set the value of $referal2 to $referal1.
In this case your code should be something like this
if($referal > 0 && is_numeric($referal) && $site['refsys'] == 1 && $site['aff_click_req'] == 0){
//code
if($user['id'] > 0){
//code
}
}elseif($referal==0){
$referal=$referal2;
}
Hope this will solve your problem.
Related
So I have a button that I want to show and hide on certain parts.
So if $unlockcourse is false AND the $courseid is 1, I would like the button to be hidden, BUT I would like it to be shown at all other times no matter what the courseidis
$courseid = ($userinfo['course']) * 1;
$mycourse = ($userinfo['id_course']) * 1;
$unlockcourse = true;
if($haspaid == 1){
$unlockcourse = false;
} else if ($haspaid == 0) {
$unlockcourse = true;
}
<?php if ($unlockcourse == false && $mycourse >= 1) { ?>
Resume Course
<?php } ?>
I am surprised how did this not throw an error. The error lies here:
if ($unlockcourse == false) && if ($mycourse == 1) && {
It should be:
if ($unlockcourse == false && $mycourse == 1) {
So what you actually want to do is show it if unlockcourse is false, and mycourse is 1. This means that to find out when to show it, you need to negate both conditions like this:
<?php if (!($unlockcourse == false && $mycourse == 1)) { ?>
Resume Course
<?php } ?>
Try Editing the following code
<?php if ($unlockcourse == false && $mycourse >= 1) { ?>
Resume Course
<?php } ?>
into
<?php if !($unlockcourse == false && $mycourse >= 1){
echo "<a href='course-work-proc.php' class='btn btn-primary'>Resume Course</a>";
}?>
This will make the button appear when your statements are true, and nothing will appear when the statement is false
I want to check if the reaction count is 0 then go in the if statement. The part without && ($app->count_reactie($topic['id']) == 0) does work but when I add this it won't work.
In the line above this code I use: implode($app->count_reactie($topic['id']))and it works so it is not that this code doesnt work. This code will return the number of reactions.
But this code down below is what I am trying to get to work.
if(isset($actiefboardid)){
$toppic = $app->get_topics($actiefboardid);
foreach($toppic as $topic){
if(isset($_SESSION['klant_id']) && ($_SESSION['klant_id'] == $topic['klant_id']) && ($app->count_reactie($topic['id']) == 0)){
}}}
Hopefully someone can help me.
Try this:
$count = $app->count_reactie($topic['id']);
if(isset($_SESSION['klant_id']) && ($_SESSION['klant_id'] == $topic['klant_id'])
&& ($count['COUNT(reactie)'] == 0)){
So, I'm currently using a elseif() in PHP but I'm having a problem with the ||.
My code is as follows:
elseif($token_24_check == 0 || $token_48_check == 0)
{
echo "<script>alert('Please enter a valid token!');</script>";
}
The problem is, it does not check either $token_24_check == 0 or $token_48_check == 0 but it checks both of them. So if one of them is false it still returns false.
Does anyone know how to fix this?
UPDATE
Here's the full code from the first line (if()) to the last line (else)
if(empty($token))
{
echo "<script>alert('Please enter a token!');</script>";
}
elseif($user_check != 0)
{
echo '<script>alert("You can only redeem 1 token.\nPlease wait until your other token has expired!");</script>';
}
elseif($token_24_check == 0 || $token_48_check == 0)
{
echo "<script>alert('Please enter a valid token!');</script>";
}
elseif($token_check != 0)
{
echo "<script>alert('Token already used! Please use a new token');</script>";
}
else
echo "<script>alert('Token successfully redeemed!');</script>";
}
As your code is written you are using else if which should be elseif
However...
as the code is written you are making a comparison with else in there try:
if($token_24_check == 0 || $token_48_check == 0)
{
echo "<script>alert('Please enter a valid token!');</script>";
}
try reversing the if/elseif
$token_24_check = 0; $token_48_check = 1; # this
# or this
$token_24_check = 1; $token_48_check = 0; # this fires the ==0
if($token_24_check == 0 || $token_48_check == 0)
{
echo "<script>alert('== 0');</script>";
}
elseif($token_24_check >= 1 || $token_48_check >= 1)
{
echo "<script>alert('>= 1');</script>";
}
Fixed it by using a different tag.
Instead of using || I used && which I should've using in the first place.
Now it checks if both conditions are 0 and will then echo the string.
Thanks everyone for your help and tips. Much appreciated!
What's wrong with this? It's not working out
// define
$prv=0;
if(isset($_GET['prv'])) {
$prv = intval($_GET['prv']);
}
// security
if($prv != 0 OR $prv != 2) {
die("<p>Error</p>");
}
This always goes through the die() part, even when prv is undefined or is defined as 2 in the url (and is 2)
And this does works:
// security
if($prv == 0 OR $prv == 2) { } else {
die("<p>Error</p>");
}
Change your if statement to:
// security
if($prv != 0 AND $prv != 2) {
die("<p>Error</p>");
}
With the OR it will always evaluate as true because when $prv == 0 it does not equal 2. Makes sense?
Whatever the value of "prv" is, it certainly cannot be both 0 and 2 at the same time, so one of the conditions is always true; that's why you get in that clause.
Break it down:
if $prv is not 0, the first condition passes and the OR succeeds
otherwise, $pev must be 0. Therefore it must be "not 2", so the OR succeeds.
Try && instead.
== replace !=
if($prv != 0 AND $prv != 2) {
die("<p>Error</p>");
}
I am new to PHP and find it very hard to explain.
I have a PHP navigation script with 5 categories and two variables relevant to my question:
$catname = 'used-cars'; // the same value for all categories
$currentpage; // pages 1 to 5
index.php of my site has $currentpage == '1'
The issue is that I need a logic that will say:
If $catname IS NOT 'used-cars', do something, BUT, IF $currentpage is equal to 1, even if $catname is 'used-cats' do it anyway
I am thinking of something like this:
if($catname != 'used-cars' && !($currentpage > '1')):
endif;
Hope you can help!
This is merely a single or condition. On the right side, $currentpage === 1 will evaluate to TRUE without regard to the value of $catname. If either part of the condition is TRUE, you'll enter the if () block to execute your code there.
if ($catname !== "used-cars" || $currentpage === 1) {
// do your thing
}
This is just:
if (strcmp($catname, 'used-cars') != 0 || $currentpage == 1)
(Careful with the string comparison.)
Alternatively, you could declare it as a boolean first:
$proceed = false;
if($catname != 'used-cars')
$proceed = true;
if($currentpage == 1)
$proceed = true;
if($proceed){
// whatever you want
}
$doflag = 0;
if($catname != 'used-cars')
{
$doflag = 1;
} else if($currentpage == 1) {
$doflag = 1;
}
if($doflag == 1) {
//do something
}
Basically instead of trying to do everything with the block, use the block to set a flag and use the flag to do something.