www.webdeveloper.com
Results 1 to 9 of 9

Thread: help with foreach

Hybrid View

  1. #1
    Join Date
    Apr 2013
    Location
    gastonia NC
    Posts
    93

    help with foreach

    Hello, someone please help with code: I get the following Hello, someone please help with code: I get the following error:

    Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH) in
    C:\xampp\htdocs\invoice\apdueprt.php on line 58
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
        <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head></head><body>
    PHP Code:
    <?php  
    //Print version 
        //Set at what record to break at 25 records per page 
        
    $BreakAT=25;  
        
    $num=0
        
    $pagenum 1;
         
    $totdue=0
           
    ?>
    HTML Code:
    <div class="display print">
    PHP Code:
    <?php 
    foreach($rows as $row): 
        if(
    $num $BreakAT == 0)
        { 
            if(
    $num>0){ echo '</table class="print">'
                 echo 
    '<div class="breakhere"></div>'
                 
    $pagenum++; } 
     
            echo 
    date('m/d/y'); 
            echo 
    " Page " $pagenum;
    ?>
    HTML Code:
    	<div class="title">Accounts Payable Report</div><br 
    	<table align="center" cellspacing=0 cellpadding=0 border=1> 
    	<thead> 
    		<tr>
    <thead> <th colspan=4></th>
    <th bgcolor="#ccffff">date</th>
    <th bgcolor="#ccffff">days</th>
    <th bgcolor="#ccffff">amt</th>
    <tr>
    <th bgcolor="#ccffff">recur?</th>
    <th bgcolor="#ccffff">acct#</th>
    <th bgcolor="#ccffff">creditor</th>
    <th bgcolor="#ccffff">purpose</th>
    <th bgcolor="#ccffff">due</th>
    <th bgcolor="#ccffff">late</th>
    <th bgcolor="#ccffff">due</th>
    		</tr> 
    	</thead>
    PHP Code:
    <?php      
        $totdue 
    += $row['amtdue'];  
              echo 

        <tr> 
            <td>' 
    $row['status'] . '</td> 
            <td>' 
    $row['acctno'] . '</td> 
            <td>' 
    $row['bname'] . '</td> 
            <td>' 
    $row['purpose'] . '</td> 
            <td>' 
    $row['duedate'] . '</td>           
             <td align=right class="currency">' 
    . ($late 120 'pastdue' $row['dayslate']) . '</td>
             <td align=right class="currency">' 
    number_format($row['amtdue'], 2'.''') . '</td>
         </tr>'

            
    $num++;
    [
    B]endforeach;[/B]  
         echo 

        <tr> 
            <th scope="row" colspan="6">Grand Total:</th> 
            <td bgcolor="#FFD4D4" class="currency">' 
    number_format($totdue2'.''') . '</td>
         </tr> 
    </table>'
    ;
        }
       
    ?>
    </div></body></html>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    891
    I realize you are trying to make your script more readable but in this format I can't make out anything. How about showing us the complete portion of the code giving you the error message. Plus - I've never seen the use of endforeach before. What are the B chars surrounding it for?

  3. #3
    Join Date
    Apr 2013
    Location
    gastonia NC
    Posts
    93
    Quote Originally Posted by ginerjm View Post
    I realize you are trying to make your script more readable but in this format I can't make out anything. How about showing us the complete portion of the code giving you the error message. Plus - I've never seen the use of endforeach before. What are the B chars surrounding it for?
    Obviously a flaw at your site. Clicking B at top should emBOLDen the selected text. Thanks, I'll
    try removing the "endforeach".

  4. #4
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    there is no alternative syntax for foreach.
    for simplicity and consistency i would recommend no using alternative syntax at all.
    PHP Code:
    <?php
    foreach ($rows as $row) {
        if (
    $num $BreakAT == 0)
        {
            if (
    $num 0) {
                echo 
    '</table class="print">',
                    
    '<div class="breakhere"></div>';
                
    $pagenum++;
            }
            echo 
    date('m/d/y');
            echo 
    " Page " $pagenum;
    ?>
    <?php
            $totdue 
    += $row['amtdue'];
            echo 
    '<tr>',
                
    '<td>' $row['status'] . '</td>',
                
    '<td>' $row['acctno'] . '</td>',
                
    '<td>' $row['bname'] . '</td>',
                
    '<td>' $row['purpose'] . '</td>',
                
    '<td>' $row['duedate'] . '</td>',
                
    '<td align=right class="currency">' . ($late 120 'pastdue' $row['dayslate']) . '</td>',
                
    '<td align=right class="currency">' number_format($row['amtdue'], 2'.''') . '</td>',
                
    '</tr>';
            
    $num++;
        }
        echo 
    '<tr>',
            
    '<th scope="row" colspan="6">Grand Total:</th>',
            
    '<td bgcolor="#FFD4D4" class="currency">' number_format($totdue2'.''') . '</td>',
            
    '</tr>',
            
    '</table>';
    }
    ?>

  5. #5
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    1,033
    Just throwing in a random note here... You can only use bbcode inside of the [ CODE] tag (not [ HTML] or [ PHP]). It might also be allowed in the [ QUOTE] tag, but I don't really know for sure.

  6. #6
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    Code:
    function test(arg) {
        alert(arg);
    }
    ^ bbcode works in code tags.
    PHP Code:
    [B]function[/Btest([I]arg[/I]) {
        [
    B]exit[/B]([I]arg[/I]);

    but not in php tags.

  7. #7
    Join Date
    Apr 2013
    Location
    gastonia NC
    Posts
    93
    thanks for your thoughts, although not dealing with my request & after close to 100
    searches with so many authoritative answers as to proper ways to deal with endforeach,
    I dug deeper into the PHP site & saw this: "endforeach does not exist". thanks again.

  8. #8
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    I had to look it up as well. I've stayed away from the alternate syntax, mostly because back in PHP 3/4 there was performance issues associated with it.

  9. #9
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    891
    Don't know what you found in "the php site" but this is a link to a section of the PHP Manual:

    http://www.php.net/manual/en/control...ive-syntax.php

    clearly describing the alternative syntaxes for a variety of the php control structures. Why one would want to use these forms I don't know. The simple, accepted format is so clear.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles