Dynadot โ€” .com Transfer

PHP Parse Error... do you see it?

Spacemail by SpaceshipSpacemail by Spaceship
Watch

Jeanco

RyanPrice.ca - DeveloperEstablished Member
Impact
4
I'm getting a parse error on line 20 - if ($x % 4 = 0) {

For those who don't know, % is for modulus division (remainder division). Anyone see why I'm getting a parse error?

PHP:
<table width="562" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width=220 align="left" bgcolor="#FFFFFF">
	pic
	</td>
    <td width=342 align="left" bgcolor="#FFFFFF">
	
	<table width="342" border="0" cellspacing="0" cellpadding="0">
	  <tr>
	<?php
		/* VARIABLES:
		$num_pics = number of pictures in teh folder
		$x = a counter
		$file_base = filename without the 3-digit number extension */
		$num_pics = 71;
		$file_base = "images/Whitby/Hockey/Atom AAA/2003-2004/thumbnails/atomaaa";		
		$x = 1;
		
		if ($num_pics >= $x) {
			if ($x % 4 = 0) {
				echo "<td width=75><img src='" . $file_base . leading_zero($x, 3, 0) . ".jpg' alt='Thumbnails' border=0></td>" . "<td width=15>ย </td></tr><tr>"; //print with new row
				$x++; //increase pic #
			}
			else {
				echo "<td width=75><img src='" . $file_base . leading_zero($x, 3, 0) . ".jpg' alt='Thumbnails' border=0></td>" . "<td width=15>ย </td>"; //print without new row
				$x++;
			}
		else {
			$x--; //x is now one greater than the number of files, so bump it down
			$y = 4 - ($x % 4); //find the number of empty rows that need filling
			
			while ($y > 0 ) {
				echo "<td width=75>ย </td><td width=15>ย </td>";
				$y--;
			}
		}
	?>
	  </tr>
	</table>

	
	</td>
  </tr>
</table>
<?php
function leading_zero( $aNumber, $intPart, $floatPart=NULL, $dec_point=NULL, $thousands_sep=NULL) {        //Note: The $thousands_sep has no real function because it will be "disturbed" by plain leading zeros -> the main goal of the function
  $formattedNumber = $aNumber;
  if (!is_null($floatPart)) {    //without 3rd parameters the "float part" of the float shouldn't be touched
   $formattedNumber = number_format($formattedNumber, $floatPart, $dec_point, $thousands_sep);
   }
  //if ($intPart > floor(log10($formattedNumber)))
   $formattedNumber = str_repeat("0",($intPart + -1 - floor(log10($formattedNumber)))).$formattedNumber;
  return $formattedNumber;
  }
  ?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I think there's a few errors in there.

You should have two equals signs there since you're comparing/evaluating rather than assigning.

if ($x % 4 == 0)

I'm not sure if that's why you're getting errors though. But I also noticed you have two else statements in a row. I think you need to change the last one to elseif or if.

You're also missing some quotes and the semi-colon at the top where you declared your variables.
 
0
•••
Yup, thanks for catching the == error.

I don't see anything wrong with how I declared variables at the top. The string has quotes and semicolon and the int variables have a semi colon.

How do nested if statements work in PHP? I come from a VB background and am used to use the

if x = 1
do something
elseif
do something
else
do soemthing
end if

Does php have an end if line of code? If not then how do you nest if statements?
 
0
•••
Hi Ryan,

The format for php comparisons with elses:

if ($x ==1) {
>>do something<<
}
elseif ($x==2) {
>> do something else <<
}
else {
>> do this <<
}

You need to use a comparison with your elseif statement and you can't have two else statements on the same 'if'.
 
0
•••
Thanks RJ but thats not what I'm after.

The first else statement was for the nested 'if' (the second if) and the other else statement was for the first 'if'. In VB this would've worked:
Code:
if x = whatever
    if y = whatever
       do this
    else
       do this
    end if
else
    do this
end if

I've got the code figured out from WHT members but am still wondering if I am able to nest if statements like this in PHP
 
0
•••
Yes, you can nest statements like that no problem.

I think I misread your code initially because it was missing a closing bracket for one of your 'if' statements, it appeared as if there were two else statements on the same if. I see what you're trying to do now.

PHP:
<table width="562" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width=220 align="left" bgcolor="#FFFFFF">
    pic
    </td>
    <td width=342 align="left" bgcolor="#FFFFFF">
    
    <table width="342" border="0" cellspacing="0" cellpadding="0">
      <tr>
    <?php
        /* VARIABLES:
        $num_pics = number of pictures in teh folder
        $x = a counter
        $file_base = filename without the 3-digit number extension */
        $num_pics = 71;
        $file_base = "images/Whitby/Hockey/Atom AAA/2003-2004/thumbnails/atomaaa";        
        $x = 1;
        
        if ($num_pics >= $x) {
            if ($x%4 == 0) {
                echo "<td width=75><img src=\"".$file_base.leading_zero($x, 3, 0).".jpg\" alt=\"Thumbnails\" border=0></td><td width=15>ย </td></tr><tr>"; //print with new row
                $x++; //increase pic #
						            } 
			else {
				echo "<td width=75><img src=\"".$file_base.leading_zero($x, 3, 0).".jpg\" alt=\"Thumbnails\" border=0></td><td width=15>ย </td>"; 
					//print without new row
					$x++;
			         } 
		}
			else {
			       $x--; //x is now one greater than the number of files, so bump it down
				   $y = 4 - ($x % 4); //find the number of empty rows that need filling
                    while ($y > 0 ) { echo "<td width=75>ย </td><td width=15>ย </td>";  $y--;    }
					}


    ?>
      </tr>
    </table>

    
    </td>
  </tr>
</table>
<?php
function leading_zero( $aNumber, $intPart, $floatPart=NULL, $dec_point=NULL, $thousands_sep=NULL) {        //Note: The $thousands_sep has no real function because it will be "disturbed" by plain leading zeros -> the main goal of the function
  $formattedNumber = $aNumber;
  if (!is_null($floatPart)) {    //without 3rd parameters the "float part" of the float shouldn't be touched
   $formattedNumber = number_format($formattedNumber, $floatPart, $dec_point, $thousands_sep);
   }
  //if ($intPart > floor(log10($formattedNumber)))
   $formattedNumber = str_repeat("0",($intPart + -1 - floor(log10($formattedNumber)))).$formattedNumber;
  return $formattedNumber;
  }
  ?>
 
Last edited:
0
•••
Ah I see... just need another }

Thanks :D
 
0
•••
Originally posted by Jeanco
Yup, thanks for catching the == error.

I don't see anything wrong with how I declared variables at the top. The string has quotes and semicolon and the int variables have a semi colon.



Oops! LOL I just took a quick look at it and I was looking where you have the multi line comments up at the top. That's why I thought you were missing some quotes and such. :D

And I also thought there was only one if statement which is why I was confused with both your else statements in a row like that. But I see them now. :)
 
0
•••
It's always a challenge debugging other programmer's scripts until you learn their programming styles. Programming languages like Perl and PHP allow multiple ways to accomplish the same task.
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back