SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    Portugal
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question PHP Count Function

    I have the PHP 5.20 and a code in php 3.20.

    in this line i have a error:
    PHP Code:
    if (count ($plano_contas)) 
    Parse error: parse error, unexpected T_IF

    Why?

    please help me

    /mrpostiga
    A beginner in PHP, start to programming in php!
    Programmer in Delphi, VB6.0 and Pascal
    I'm Portuguese . Sorry for my English!

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You forgot the right side of the condition. Use something like:

    if (count($plano_contas) > 0)
    Either that, or it's in another part of your code. Check the lines just above to ensure the proper { and } marks are there.

    Hope that helps!
    Kiopa Software -- Demo Now Online! Check it out!
    Goal: Consolidate all data & tools you use on a daily basis.
    Grand opening special, licenses FREE for a limited time.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    Portugal
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (count ($plano_contas)<>0)
     {
        foreach (
    $plano_contas as $dbconta) {

            
    $idconta ;
            
    $descricao "" ;
    //        $conta = 0 ;

            
            
    $idconta trim ($dbconta['cntmst_cpoc']) ;
            
    $descricao trim ($dbconta['CNTMST_DESI']) ;


    //        echo "idconta = ".$idconta."  ".$descricao."<br>" ;    

            
    if (strlen ($descricao) ) {
            
    // ir buscar os valores consoante os graus
                
    if (strlen ($idconta) == 2) {
                    
    $my_conta $dbconta ;
                    
    $my_conta['valores'] = $plano_bigcontas[$idconta]['valores'] ;
                }
                else {
                    
    $my_conta $dbconta ;
                }
                            
                
    $mes_deb $my_conta['valores']['mes_deb'] ;
                
    $mes_cred $my_conta['valores']['mes_cred'] ;
            
                
    $acum_deb $my_conta['valores']['acum_deb'] ;
                
    $acum_cred $my_conta['valores']['acum_cred'] ;
            
                
    $total_cred $mes_cred $acum_cred ;
                
    $total_deb $mes_deb $acum_deb ;
            
                
    $saldo $total_deb $total_cred ;

    //            echo $mes_deb." ".$mes_cred." ".$acum_deb." ".$acum_cred." ".$saldo."<hr>" ;

                
    if (strlen ($idconta) == 2) {
                    
    $conta $doc->create_element ("conta") ;
                    
    $conta->set_attribute ("ID"$idconta) ;
                    
    add_element ($doc$conta"descricao"$descricao) ;
                
                    
    $valores $doc->create_element ("valores") ;

                    
    $mes $doc->create_element ("mes") ;
                    
    $mes->set_attribute ("deb"$mes_deb) ;
                    
    $mes->set_attribute ("cred"$mes_cred) ;

                    
    $acumulados $doc->create_element ("acumulados") ;
                    
    $acumulados->set_attribute ("deb"$acum_deb) ;
                    
    $acumulados->set_attribute ("cred"$acum_cred) ;

                    
    $actuais $doc->create_element ("actuais") ;
                    
    $actuais->set_attribute ("sald"$saldo) ;

                    
    $valores->append_child ($mes) ;
                    
    $valores->append_child ($acumulados) ;
                    
    $valores->append_child ($actuais) ;

                    
    $conta->append_child ($valores) ;


    this is my if code.
    A beginner in PHP, start to programming in php!
    Programmer in Delphi, VB6.0 and Pascal
    I'm Portuguese . Sorry for my English!

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please post the lines before that.

  5. #5
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems as though you havent closed a query with a ; before the if statement, other than that as stereofrog said, post your code
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  6. #6
    malloc
    Join Date
    Nov 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You forgot the right side of the condition.
    No he didn't, there's nothing wrong with if(count($x)).

    The problem is in the line(s) preceeding this if statement. If for example there is a missing semicolon, the "IF" would be unexpected.

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    Portugal
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    //$doc = domxml_new_doc("1.0");//(old)
    $doc = new DOMDocument("1.0");
    $doc $doc->createElement("canvas");
    //$canvas = $doc->create->element("canvas");//(old)
    $canvas =$doc->appendChild($canvas);
    //$canvas = $doc->append->child($canvas);//(old)
    $canvas->setAttribute('version','2.0');
    /////////////////////////////////////////
    $balancete=$doc->createElement("balancete")
    //$balancete = $doc->create->element ("balancete") ;//(old) 
    this is my code before the if

    I substitute the code with //(old)

    Please correct with they are wrong
    A beginner in PHP, start to programming in php!
    Programmer in Delphi, VB6.0 and Pascal
    I'm Portuguese . Sorry for my English!

  8. #8
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    //$doc = domxml_new_doc("1.0");//(old)
    $doc = new DOMDocument("1.0");
    $doc $doc->createElement("canvas");
    //$canvas = $doc->create->element("canvas");//(old)
    $canvas =$doc->appendChild($canvas);
    //$canvas = $doc->append->child($canvas);//(old)
    $canvas->setAttribute('version','2.0');
    /////////////////////////////////////////
    $balancete=$doc->createElement("balancete"); //PUT SEMICOLON IN
    //$balancete = $doc->create->element ("balancete") ;//(old) 
    Here you go, put the semicolon on the last line of functional code
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    Portugal
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrpostiga
    PHP Code:
    //$doc = domxml_new_doc("1.0");//(old)
    $doc = new DOMDocument("1.0");
    $doc $doc->createElement("canvas");
    //$canvas = $doc->create->element("canvas");//(old)
    $canvas =$doc->appendChild($canvas);
    //$canvas = $doc->append->child($canvas);//(old)
    $canvas->setAttribute('version','2.0');
    /////////////////////////////////////////
    $balancete=$doc->createElement("balancete");
    //$balancete = $doc->create->element ("balancete") ;//(old) 
    is in this code any Error?
    who that is the best way? with the old code or with the new code?
    A beginner in PHP, start to programming in php!
    Programmer in Delphi, VB6.0 and Pascal
    I'm Portuguese . Sorry for my English!

  10. #10
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's a different question you are asking now ... is DOMDocument class better than the domxml_new_doc method. I have absolutely no idea as I have no idea what are either of these classes/methods!
    Ian Anderson
    www.siteguru.co.uk

  11. #11
    SitePoint Enthusiast
    Join Date
    May 2006
    Location
    Portugal
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i didnt understood that i have used 2 different classes
    lol
    A beginner in PHP, start to programming in php!
    Programmer in Delphi, VB6.0 and Pascal
    I'm Portuguese . Sorry for my English!

  12. #12
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You might want to change:
    PHP Code:
     if (count ($plano_contas)<>0
    To:
    PHP Code:
     if (count($plano_contas) != 0
    "<>" means not equal in VB but in php you have to use "!="
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  13. #13
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can actually use <> in php, its just not common. its the same as !=

    http://www.php.net/manual/en/languag...comparison.php

  14. #14
    malloc
    Join Date
    Nov 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (count($plano_contas)) 
    surely


Bookmarks

Posting Permissions

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