Need assistance locating syntax error - php

The following code is returning a syntax error in the second elseif statement:
if(($Rec["gradyear"] = $mydate[year] && $mydate[month] IN ("January","February","March","April","June","July")) || ($Rec["gradyear"] = $mydate[year] -1 && $mydate[month] IN ("August","September","October","November","December"))) {
$bgcolor="#00FF00";
} elseif(($Rec["gradyear"] = $mydate[year] -1 && $mydate[month] IN ("January","February","March","April","June","July")) || ($Rec["gradyear"] = $mydate[year] -2 && $mydate[month] IN ("August","September","October","November","December"))) {
$bgcolor="#FFFF00";
} elseif(($Rec["gradyear"] = $mydate[year] -2 && $mydate[month] IN ("January","February","March","April","June","July")) || ($Rec["gradyear"] = $mydate[year] -3 && $mydate[month] IN ("August","September","October","November","December"))) {
$bgcolor="#FF0000"; $fontcolor="#FFFFFF";
}
For the life of me, I cannot locate it. Any help will be greatly appreciated.
Also, I apologize in advance if I'm not including enough information. This is my first time posting here, so please be gentle. :)

In is not valid.
Use in_array in php.
For example:
in_array($mydate[month] ,
array("January","February","March","April","June","July")
);

Replace "IN" with in_array for starters,change "$mydate[month]" to "$mydate['month']"...from a first glance...try to simplify your if`s...

Related

Why is my IF statement not working to define membership level?

I am very new to PHP and trying to get an IF statement to work to change the membership level based on the possibility of multiple answers provided in the registration form. However, it's not working. If anyone can help me understand what I am doing wrong/missing that would be a great help. Here is my code. Thank you.
function my_pmpro_checkout_level($level)
{
if ( ! empty( $_REQUEST['registrationlevel']) && $level->id == '1' ) {
if (( $_REQUEST['registrationlevel'] == 'eligibleforlimited' && $_REQUEST['experience'] != 'morethansixyears') || ($_REQUEST['registrationlevel'] == 'eligibleforlimited' && $_REQUEST['timeassesment'] == 'no')) {
$level->id = '3';
} elseif ( $_REQUEST['registrationlevel'] == 'eligibleforprovisional' && $_REQUEST['experience'] != 'noexperience') {
$level->id = '3'}
}
return $level;
}
add_filter("pmpro_checkout_level", "my_pmpro_checkout_level");

if isset statement is incorrect

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)){

PHP IF construct when dealing with a part that is an exception

I'm having some trouble getting my code to work. And I lost my overview. Who can give me some insight?
I'm looking for how to build an IF construct.
If I would describe the IF construct in words:
MismatchBundle = true unless (adminPass = true & user = admin)
I wrote the following code, but this didn't seem to work:
if (($MismatchBundle == true) && ($adminPass != true && $thisUser['rankid'] != 1)
Anyone who knows how to get the 'unless' part in the code?
What about this?
if (($MismatchBundle == true) && !($adminPass == true && $thisUser['rankid'] == 1)
Is this allowed with the ! before a () section?
if (($MismatchBundle == true) && !($adminPass == true && $thisUser['rankid'] == 1)
Using ! on the entire section within ( ) worked as intended.

php loop display result if isset and matches the given value

I am sorry to ask such a question but am bit confused about this.
I am having simple variables defined.
$a =1;
$b=2;
$c=3;
$d="";
for($i=0;$i<10;$i++)
{
$testa = 1;
$testb = 4;
$testc = 3;
$testd = 7;
if($a!="" || $b!="" || $c!="" || $d!="") {
if($a==$testa && $b==$testb && $c==$testc && $d==$testd) {
echo $testa;
echo $testb;
echo $testc;
echo $testd;
}
}
}
This is sample php code.
what I need is that I have variables defined at top. SO in my loop i want to display result if user has any 1 variable but in below loop display result based on "and" parameter.
I actually want to skip the empty variable. SO in this case, I want as $d is empty, so it should be prevented somehow from if($a==$testa && $b==$testb && $c==$testc && $d==$testd) from here.
Any help is really appreciated.
To skip the empty values from the check, use ||
if ( ... && (empty($d) || $d == $testd)) {
Then if you also want to skip it in your echos :
echo !empty($d) ? $testd : '';

If statement structure in PHP

I keep getting an error with the following bit of code. It is probably some small thing but I don't see what is wrong.
while($row = mysql_fetch_array($result))
{
$varp = $row['ustk_retail'];
if ($varp<80000) { $o1 = 1; }
if (($varp=>80000) && ($varp<100000)) { $o2 = "1"; }
if (($varp=>100000) && ($varp<120000)) { $o3 = "1"; }
if (($varp=>120000) && ($varp<140000)) { $o4 = "1"; }
if (($varp=>140000) && ($varp<160000)) { $o5 = "1"; }
if (($varp=>160000) && ($varp<180000)) { $o6 = "1"; }
if (($varp=>180000) && ($varp<200000)) { $o7 = "1"; }
if (($varp=>200000) && ($varp<220000)) { $o8 = "1"; }
if (($varp=>220000) && ($varp<240000)) { $o9 = "1"; }
if (($varp=>240000) && ($varp<260000)) { $o10 = "1"; }
if (($varp=>260000) && ($varp<280000)) { $o11 = "1"; }
if (($varp=>280000) && ($varp<300000)) { $o12 = "1"; }
if ($varp>=300000) { $o13 = "1"; }
}
Running php -l (lint) on your code I get a
Parse error: syntax error, unexpected T_DOUBLE_ARROW
The T_DOUBLE_ARROW token is what PHP expects when assigning array values to array keys.
When comparing for Greater than or equal to the PHP Parser expects T_IS_GREATER_OR_EQUAL, meaning you have to use >= instead of =>.
See
the chapter on Comparison Operators in the PHP Manual and
the List of Parser Tokens in the PHP Manual
Greater than or equal to is >= sign, not =>
Update:
You are right. It's small but hard to find mistake.
It took me to split whole line into pieces to see where the problem is:
<?php
if
(
$varp
=>
80000
)
So, it says parse error on line 5 and I had to doublecheck this operator.
Of course, at first I separated the problem line from the rest of the code to be certain.
You have an expression error.
$varp=>220000 // is not a valid php expression
=> operator is used to assign values in arrays like:
$x = array( 'foo' => 'bar');
>= is the comparation assigment greater than or equal
You have made a mistake in the if conditions. The greater than Equal to sign is >= and not =>.
The answer has already been given but thought this was neat enough to share:
PHP accepts boolean expressions in it's switch statement.
switch(TRUE) {
case $range <= 10: echo "range below or equal to 10"; break;
case $range <= 20: echo "range above 10 below or equal to 20"; break;
case $range <= 30: echo "range above 20 below or equal to 30"; break;
default: echo "high range";
}
In my opinion this generates the cleanest most readable code.
This is more readable and compact way to do the same:
$ranges = range(300000, 80000, -20000);
$index = 1;
$varp = 220001;
foreach ($ranges as $i => $range) {
if ($varp >= $range) {
$index = 13 - $i;
break;
}
}
${'o' . $index} = 1;
Anyway - I think you're doing something wrong with using variable name of result.
You probably want to change ($varp=300000) to ($varp==300000) and it might help to enclose the full if-statement inside (), like this
if($varp80000 && $varp100000 && $varp120000 && $varp140000 && $varp160000 && $varp180000 && $varp200000 && $varp220000 && $varp240000 && $varp260000 && $varp280000 && $varp==300000) { $o13 = "1"; }
On another note, where to these strange $varp#### variables come from?
Not sure whether the code you've posted has gotten messed up somehow, but it looks like you're missing "==" in some of the if conditions. Also, as Skilldrick pointed out, the whole if condition should be in parentheses
"Greater than or equal to is >= NOT =>. You use => for arrays for keys/values.
Add one more bracket around the conditions in if....
if ( ($varp80000) && ($varp100000) && ($varp120000) && ($varp140000) && ($varp160000) && ($varp180000) && ($varp200000) && ($varp220000) && ($varp240000) && ($varp260000) && ($varp280000) && ($varp=300000) ) { $o13 = "1"; }

Categories