[advanced search]
Results from the most recent live auction are here.
20 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 12-31-2003, 11:00 AM   · #1
Jeanco
RyanPrice.ca - Developer
 
Name: Ryan Price
Trader Rating: (28)
Join Date: Dec 2003
Posts: 1,331
NP$: 34.00 (Donate)
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 % 4 = 0) {
                echo
"<td width=75><img src='" . $file_base . leading_zero($x, 3, 0) . ".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($x, 3, 0) . ".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 = 4 - ($x % 4); //find the number of empty rows that need filling
            
            
while ($y > 0 ) {
                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
  
$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;
  }
  
?>


Please register or log-in into NamePros to hide ads
__________________
Ryan Price - Webmaster
www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign
Jeanco is offline   Reply With Quote
Old 12-31-2003, 11:18 AM   · #2
deadserious
Senior Member
 
Trader Rating: (13)
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (Donate)
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   Reply With Quote
Old 12-31-2003, 11:33 AM   · #3
Jeanco
RyanPrice.ca - Developer
 
Name: Ryan Price
Trader Rating: (28)
Join Date: Dec 2003
Posts: 1,331
NP$: 34.00 (Donate)
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   Reply With Quote
Old 12-31-2003, 12:33 PM   · #4
-RJ-
Mr. Mayor
 
-RJ-'s Avatar
 
Name: Ron James
Location: Bay Area, CA
Trader Rating: (221)
Join Date: Feb 2003
Posts: 12,681
NP$: 17646.98 (Donate)
-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute
Autism Find Marrow Donors! Save The Children Cystic Fibrosis Ethan Allen Fund Myanmar Relief
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'.
__________________
Twitter http://twitter.com/domainbuyer
-RJ- is offline  
  Reply With Quote
Old 12-31-2003, 12:36 PM   · #5
Jeanco
RyanPrice.ca - Developer
 
Name: Ryan Price
Trader Rating: (28)
Join Date: Dec 2003
Posts: 1,331
NP$: 34.00 (Donate)
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:
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   Reply With Quote
Old 12-31-2003, 12:42 PM   · #6
-RJ-
Mr. Mayor
 
-RJ-'s Avatar
 
Name: Ron James
Location: Bay Area, CA
Trader Rating: (221)
Join Date: Feb 2003
Posts: 12,681
NP$: 17646.98 (Donate)
-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute
Autism Find Marrow Donors! Save The Children Cystic Fibrosis Ethan Allen Fund Myanmar Relief
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%4 == 0) {
                echo
"<td width=75><img src=\"".$file_base.leading_zero($x, 3, 0).".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($x, 3, 0).".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 = 4 - ($x % 4); //find the number of empty rows that need filling
                    
while ($y > 0 ) { 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
  
$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;
  }
  
?>
__________________
Twitter http://twitter.com/domainbuyer

Last edited by -RJ- : 12-31-2003 at 12:47 PM.
-RJ- is offline  
  Reply With Quote
Old 12-31-2003, 12:49 PM   · #7
Jeanco
RyanPrice.ca - Developer
 
Name: Ryan Price
Trader Rating: (28)
Join Date: Dec 2003
Posts: 1,331
NP$: 34.00 (Donate)
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   Reply With Quote
Old 12-31-2003, 02:16 PM   · #8
deadserious
Senior Member
 
Trader Rating: (13)
Join Date: Aug 2002
Posts: 1,300
NP$: 2.85 (Donate)
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   Reply With Quote
Old 12-31-2003, 02:33 PM   · #9
-RJ-
Mr. Mayor
 
-RJ-'s Avatar
 
Name: Ron James
Location: Bay Area, CA
Trader Rating: (221)
Join Date: Feb 2003
Posts: 12,681
NP$: 17646.98 (Donate)
-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute-RJ- has a reputation beyond repute
Autism Find Marrow Donors! Save The Children Cystic Fibrosis Ethan Allen Fund Myanmar Relief
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.
__________________
Twitter http://twitter.com/domainbuyer
-RJ- is offline  
  Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
Proof is in the Parking Proof is in the Parking Proof is in the Parking
Advertise your business at NamePros
All times are GMT -7. The time now is 09:54 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0