Click to See Complete Forum and Search --> : Simple problem adding


Perfidus
12-10-2003, 12:49 PM
I would like to add 1 to $numsemanas everytime variables are =! 0, but I'm trying the wrong way, I guess.
How can I do it?

<?
$numsemanas=0;
if ($row['ene1t']=!0){$numsemanas=$numsemanas+1;}
if ($row['ene2t']=!0){$numsemanas=$numsemanas+1;}
if ($row['ene3t']=!0){$numsemanas=$numsemanas+1;}
?>

pyro
12-10-2003, 01:05 PM
Not equal is !=, not =!.

Also, you can use $var++ instead of $var = $var + 1

<?PHP
$numsemanas = 0;
if ($row['ene1t'] != 0) {
$numsemanas++;
}
if ($row['ene2t'] != 0) {
$numsemanas++;
}
if ($row['ene3t'] != 0) {
$numsemanas++;
}
?>

Perfidus
12-10-2003, 01:14 PM
I get this error:
Parse error: parse error, expecting `','' or `';'' in /chs/p1/costa4seasons.com/home/html/procesandoreserva.php on line 38

In this line:

if ($row['ene1t']!=0){$numsemanas++;}

By the way is the same error I got before when old code:

if ($row['ene1t']=!0){$numsemanas=$numsemanas+1;}

In same line

pyro
12-10-2003, 01:17 PM
Do you have a ; on the end of the line above it?

Perfidus
12-10-2003, 01:20 PM
That's the way my code looks!
<?$numsemanas=0;
if ($row['ene1t']!=0){$numsemanas++;}
if ($row['ene2t']!=0){$numsemanas++;}

pyro
12-10-2003, 01:23 PM
Hmm... This worked fine for me:

<?PHP
$row = array('ene1t' => 0, 'ene2t' => 1, 'ene3t' => 2); # temp array
$numsemanas = 0;
if ($row['ene1t'] != 0) {
$numsemanas++;
}
if ($row['ene2t'] != 0) {
$numsemanas++;
}
if ($row['ene3t'] != 0) {
$numsemanas++;
}
echo $numsemanas;
?>You sure you are looking at the correct line? If so, try showing your complete code.