NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP Parse Error... do you see it?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 12-31-2003, 11:00 AM THREAD STARTER               #1 (permalink)
RyanPrice.ca - Developer
Join Date: Dec 2003
Posts: 1,328
Jeanco is a jewel in the roughJeanco is a jewel in the roughJeanco is a jewel in the rough
 



PHP Parse Error... do you see it?


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 Code:
<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 0) {
                echo 
"<td width=75><img src='" $file_base leading_zero($x30) . ".jpg' alt='Thumbnails' border=0></td>" "<td width=15>&nbsp;</td></tr><tr>"//print with new row
                
$x++; //increase pic #
            
}
            else {
                echo 
"<td width=75><img src='" $file_base leading_zero($x30) . ".jpg' alt='Thumbnails' border=0></td>" "<td width=15>&nbsp;</td>"//print without new row
                
$x++;
            }
        else {
            
$x--; //x is now one greater than the number of files, so bump it down
            
$y - ($x 4); //find the number of empty rows that need filling
            
            
while ($y ) {
                echo 
"<td width=75>&nbsp;</td><td width=15>&nbsp;</td>";
                
$y--;
????: NamePros.com http://www.namepros.com/programming/16186-php-parse-error-do-you-see.html
            }
        }
    
?>
????: NamePros.com http://www.namepros.com/showthread.php?t=16186
      </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 + -floor(log10($formattedNumber)))).$formattedNumber;
  return 
$formattedNumber;
  }
  
?>
__________________
Ryan Price - Webmaster
www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign
Jeanco is offline  
Old 12-31-2003, 11:18 AM   #2 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



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.
deadserious is offline  
Old 12-31-2003, 11:33 AM THREAD STARTER               #3 (permalink)
RyanPrice.ca - Developer
Join Date: Dec 2003
Posts: 1,328
Jeanco is a jewel in the roughJeanco is a jewel in the roughJeanco is a jewel in the rough
 



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?
__________________
Ryan Price - Webmaster
www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign
Jeanco is offline  
Old 12-31-2003, 12:33 PM   #4 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease
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'.
__________________
@DomainBuyer facebook
RJ is offline  
Old 12-31-2003, 12:36 PM THREAD STARTER               #5 (permalink)
RyanPrice.ca - Developer
Join Date: Dec 2003
Posts: 1,328
Jeanco is a jewel in the roughJeanco is a jewel in the roughJeanco is a jewel in the rough
 



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:
????: NamePros.com http://www.namepros.com/showthread.php?t=16186
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
__________________
Ryan Price - Webmaster
www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign
Jeanco is offline  
Old 12-31-2003, 12:42 PM   #6 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease
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 Code:
<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%== 0) {
                echo 
"<td width=75><img src=\"".$file_base.leading_zero($x30).".jpg\" alt=\"Thumbnails\" border=0></td><td width=15>&nbsp;</td></tr><tr>"//print with new row
                
$x++; //increase pic #
                                    

            else {
                echo 
"<td width=75><img src=\"".$file_base.leading_zero($x30).".jpg\" alt=\"Thumbnails\" border=0></td><td width=15>&nbsp;</td>"
                    
//print without new row
                    
$x++;
                     } 
        }
            else {
                   
$x--; //x is now one greater than the number of files, so bump it down
                   
$y - ($x 4); //find the number of empty rows that need filling
                    
while ($y ) { echo "<td width=75>&nbsp;</td><td width=15>&nbsp;</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
????: NamePros.com http://www.namepros.com/showthread.php?t=16186
  
$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 + -floor(log10($formattedNumber)))).$formattedNumber;
????: NamePros.com http://www.namepros.com/showthread.php?t=16186
  return 
$formattedNumber;
  }
  
?>
__________________
@DomainBuyer facebook
Last edited by -RJ-; 12-31-2003 at 12:47 PM.
RJ is offline  
Old 12-31-2003, 12:49 PM THREAD STARTER               #7 (permalink)
RyanPrice.ca - Developer
Join Date: Dec 2003
Posts: 1,328
Jeanco is a jewel in the roughJeanco is a jewel in the roughJeanco is a jewel in the rough
 



Ah I see... just need another }

Thanks
__________________
Ryan Price - Webmaster
www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign
Jeanco is offline  
Old 12-31-2003, 02:16 PM   #8 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



Quote:
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.

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.
deadserious is offline  
Old 12-31-2003, 02:33 PM   #9 (permalink)
RJ
NamePros Webmaster


 
RJ's Avatar
Join Date: Feb 2003
Posts: 12,930
RJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatnessRJ Has achieved greatness
 



Find Marrow Donors! Cystic Fibrosis Parkinson's Disease
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.
__________________
@DomainBuyer facebook
RJ is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:51 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger