Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: PHP Programming

  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Programming

    Hi,
    Can someone please help me out with this error:

    Parse error: syntax error, unexpected T_STRING in /var/www/html/newmoe/functions.inc on line 696

    The code is as follows:

    677 print "<script language=\"JavaScript\">\n
    678 function departmentClass()\n
    679 {\n
    680 for ($i=0; $i<arguments.length; $i++)\n
    681 {\n
    682 this[departmentClass.arguments[$i]] = new Array2D(100,100);\n
    683 }\n
    684 }\n
    685
    686 function Array2D(dim1, dim2)\n
    687 {\n
    688 for ($i=0; $i<dim1; ++$i)\n
    689 {\n
    690 this[$i] = new Array(dim2);\n
    691 }\n
    692 this.length = new Array(dim1,dim2);\n;
    693 }\n
    694 function department()\n
    695 {\n
    696 $sql = "select *,Employees.LastName eeLastName,Employees.FirstName eeFirstName,Orders.EmployeeID eeID from Orders LEFT JOIN Employees on Orders.EmployeeID=Employees.UserID where OrderID=".$wo_num;
    697 }\n";
    698 echo "var departments = new departmentClass(";
    699 for ($i=0; $i<$numrows5; $i++)
    700 {
    701 $this_prefix = mysql_result($result5,$i,Prefix);
    702 echo "\"$this_prefix\"";
    703 if ($i + 1<$numrows5)
    704 {
    705 echo ",";
    706 }
    707 }
    708 echo ");\n";
    709
    710 for ($i=0; $i<$numrows5;$i++)
    711 {
    712 $start_prefix = mysql_result($result5,$i,Prefix);
    713 $result6=get_departments($start_prefix);
    714 $numrows6=mysql_num_rows($result6);
    715 for ($j=0; $j<$numrows6; $j++)
    716 {
    717 $dept_name = mysql_result($result6,$j,Department);
    718 $dept_id = mysql_result($result6,$j,DepartmentID);
    719 echo "departments[\"$start_prefix\"][$j].value=\"$dept_id\";\n";
    720 echo "departments[\"$start_prefix\"][$j].name=\"$dept_name\";\n";
    721 }
    722 }
    723 echo "</script>\n";

    Thanks.
    Last edited by saxena; 09-07-2008 at 06:00 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Which is your editor? Please edit your post by removing the line numbers, as it's very hard for us to have a try. Also, wrap your code in [php][/php] tags to enhance the readability.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am doing it in vi editor on LINUX.

    PHP Code:
                    print "<script language=\"JavaScript\">\n
              function departmentClass()\n
              {\n
                 for ($i=0; $i<arguments.length; $i++)\n
                  {\n
                    this[departmentClass.arguments[$i]] = new Array2D(100,100);\n
                  }\n
              }\n
        
              function Array2D(dim1, dim2)\n
              {\n
                  for ($i=0; $i<dim1; ++$i)\n
                  {\n
                    this[$i] = new Array(dim2);\n
                  }\n
                 this.length = new Array(dim1,dim2);\n;
              }\n
              function department()\n
              {\n
                 $sql = "
    select *,Employees.LastName eeLastName,Employees.FirstName eeFirstName,Orders.EmployeeID eeID from Orders LEFT JOIN Employees on Orders.EmployeeID=Employees.UserID where OrderID=".$wo_num;
               }\n"
    ;
              echo 
    "var departments = new departmentClass(";
              for (
    $i=0$i<$numrows5$i++)
              {
                
    $this_prefix mysql_result($result5,$i,Prefix);
                echo 
    "\"$this_prefix\"";
                if (
    $i 1<$numrows5)
                {
                  echo 
    ",";
                }
              }
              echo 
    ");\n";
        
              for (
    $i=0$i<$numrows5;$i++)
              {
                 
    $start_prefix mysql_result($result5,$i,Prefix);
                 
    $result6=get_departments($start_prefix);
                 
    $numrows6=mysql_num_rows($result6);
                 for (
    $j=0$j<$numrows6$j++)
                 {
                  
    $dept_name mysql_result($result6,$j,Department);
                  
    $dept_id mysql_result($result6,$j,DepartmentID);
                   echo 
    "departments[\"$start_prefix\"][$j].value=\"$dept_id\";\n";
                   echo 
    "departments[\"$start_prefix\"]$j].name=\"$dept_name\";\n";
                 }
              }
              echo 
    "</script>\n"
    Thanks.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    you post in the wrong forum, this is the javascript forum, ask one of the moderators to move the thread in the php forum, please.

    Quote Originally Posted by saxena View Post
    I am doing it in vi editor on LINUX.

    PHP Code:
                    print "<script language=\"JavaScript\">\n
              function departmentClass()\n
              {\n
                 for ($i=0; $i<arguments.length; $i++)\n
                  {\n
                    this[departmentClass.arguments[$i]] = new Array2D(100,100);\n
                  }\n
              }\n
        
              function Array2D(dim1, dim2)\n
              {\n
                  for ($i=0; $i<dim1; ++$i)\n
                  {\n
                    this[$i] = new Array(dim2);\n
                  }\n
                 this.length = new Array(dim1,dim2);\n;
              }\n
              function department()\n
              {\n
                 $sql = "
    select *,Employees.LastName eeLastName,Employees.FirstName eeFirstName,Orders.EmployeeID eeID from Orders LEFT JOIN Employees on Orders.EmployeeID=Employees.UserID where OrderID=".$wo_num;
               }\n"
    ;
              echo 
    "var departments = new departmentClass(";
              for (
    $i=0$i<$numrows5$i++)
              {
                
    $this_prefix mysql_result($result5,$i,Prefix);
                echo 
    "\"$this_prefix\"";
                if (
    $i 1<$numrows5)
                {
                  echo 
    ",";
                }
              }
              echo 
    ");\n";
        
              for (
    $i=0$i<$numrows5;$i++)
              {
                 
    $start_prefix mysql_result($result5,$i,Prefix);
                 
    $result6=get_departments($start_prefix);
                 
    $numrows6=mysql_num_rows($result6);
                 for (
    $j=0$j<$numrows6$j++)
                 {
                  
    $dept_name mysql_result($result6,$j,Department);
                  
    $dept_id mysql_result($result6,$j,DepartmentID);
                   echo 
    "departments[\"$start_prefix\"][$j].value=\"$dept_id\";\n";
                   echo 
    "departments[\"$start_prefix\"]$j].name=\"$dept_name\";\n";
                 }
              }
              echo 
    "</script>\n"
    Thanks.
    are few problem:
    1. it's not clear where the print from line 677 ends, probably before function departament.
    This produce the error.
    2. incorect select query:
    Code:
    $sql = "select *,Employees.LastName eeLastName,Employees.FirstName eeFirstName,Orders.EmployeeID eeID from Orders LEFT JOIN Employees on Orders.EmployeeID=Employees.UserID where OrderID=".$wo_num;
    missing comma probably between Employees.FirstName and eeFirstName and between Orders.EmployeeID and eeID.
    or
    if `FirstName eeFirstName` and `EmployeeID eeID` are field name you must write as:
    Code:
    $sql = "select *,Employees.LastName eeLastName,`Employees.FirstName eeFirstName`,Orders.EmployeeID eeID from Orders LEFT JOIN Employees on Orders.EmployeeID=Employees.UserID where OrderID=".$wo_num;
    3. function department don't do nothing, just asign a string to a local variable $sql.

    regards

  • #5
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Where is the printing of the Javascript supposed to end?

    The error comes because the " after $sql= is the first quote since the one after the print statement. Maybe you want to end the print before that?

    What is with all the \n's?

    Oesxyl, in the sql, he is using the implicit 'AS' keyowrd, saying in effect SELECT Employees.LastName AS eeLastName, etc, so using quotes would not produce the intended results.

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by julian View Post
    Where is the printing of the Javascript supposed to end?

    The error comes because the " after $sql= is the first quote since the one after the print statement. Maybe you want to end the print before that?

    What is with all the \n's?

    Oesxyl, in the sql, he is using the implicit 'AS' keyowrd, saying in effect SELECT Employees.LastName AS eeLastName, etc, so using quotes would not produce the intended results.
    1. did you read what I said?
    2. where did you know that "LastName eeLastName" is not a field name with spaces inside as I assume? ( well, anyway mine and yours are assumption, , op must make this clear)

    best regards

  • #7
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I apologize for posting in the wrong forum.But I thank all of you for giving such prompt replies.

    The printing of Javascript ends after the function department on line 697.
    But as oesxyl said, I've now ended it before this function i.e at the end of function Array2D.
    I have assigned $sql to $str and have removed all \n's.
    my code looks like this now:

    PHP Code:

    print "<script language=\"JavaScript\">"
         
          
    function departmentClass()
          {
             for (
    $i=0$i<arguments.length$i++)
             {
               
    this[departmentClass.arguments[$i]] = new Array2D(100,100);
             }
          }

          function 
    Array2D(dim1dim2)
          {
             for (
    $i=0$i<dim1; ++$i)
             {
               
    this[$i] = new Array(dim2);
             }
            
    this.length = new Array(dim1,dim2);
          }
    ";
           

          function department()
          {
            $sql = "
    select *,Employees.LastName eeLastName,Employees.FirstName eeFirstName,Orders.EmployeeID eeID from Orders;
            
    $str $sql;
          }

         echo 
    "var departments = new departmentClass(";
         for (
    $i=0$i<$numrows5$i++)
         {
           
    $this_prefix mysql_result($result5,$i,Prefix);
           echo 
    "\"$this_prefix\"";
           if (
    $i 1<$numrows5)
           {
             echo 
    ",";
           }
         }
         echo 
    ");";
      
         for (
    $i=0$i<$numrows5;$i++)
         {
            
    $start_prefix mysql_result($result5,$i,Prefix);
            
    $result6=get_departments($start_prefix);
            
    $numrows6=mysql_num_rows($result6);
            for (
    $j=0$j<$numrows6$j++)
            {
              
    $dept_name mysql_result($result6,$j,Department);
              
    $dept_id mysql_result($result6,$j,DepartmentID);
              echo 
    "departments[\"$start_prefix\"][$j].value=\"$dept_id\";";
              echo 
    "departments[\"$start_prefix\"][$j].name=\"$dept_name\";";
            }
         }
         echo 
    "</script>"
    but now I get this error:

    Parse error: syntax error, unexpected T_FUNCTION in /var/www/html/newmoe/functions.inc on line 679

    that points to the foloowing line: function departmentClass()

    Thanks.

  • #8
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and...

    LastName eeLastName is NOT a field name with space...
    Julian has identified it correctly.Iam trying to rename the field LastName as eeLastName.

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by saxena View Post
    I apologize for posting in the wrong forum.But I thank all of you for giving such prompt replies.

    The printing of Javascript ends after the function department on line 697.
    But as oesxyl said, I've now ended it before this function i.e at the end of function Array2D.
    I have assigned $sql to $str and have removed all \n's.
    my code looks like this now:
    remove " on the first line:
    PHP Code:
    print "<script language=\"JavaScript\">
         
          function departmentClass()
          {
             for ($i=0; $i<arguments.length; $i++)
             {
               this[departmentClass.arguments[$i]] = new Array2D(100,100);
             }
          }

          function Array2D(dim1, dim2)
          {
             for ($i=0; $i<dim1; ++$i)
             {
               this[$i] = new Array(dim2);
             }
            this.length = new Array(dim1,dim2);
          }"

    PHP Code:
          function department()
          {
            
    $sql "select *,Employees.LastName eeLastName,Employees.FirstName eeFirstName,Orders.EmployeeID eeID from Orders;
            $str = $sql;
            // still don't do nothing, probably must be:
            // return $sql;
            // or if $str
          } 
    vim have hilightsyntax, use it, or use emacs with php-mode.

    best regards
    Last edited by oesxyl; 09-08-2008 at 04:34 PM.

  • #10
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot...

    The " at the end of my print statement was causing the error...
    Its actually working even if i don't put any "return" or "if" in the function department().

    More queries cuming up...watch out!!!
    Last edited by saxena; 09-08-2008 at 05:12 PM.

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    ask one of the moderators to move the thread in php forum, this way you get answers from more people. Thank you.

    it's not ok what is here. You generate html and javascript using php, the perfect way to don't know when start js and when php:
    PHP Code:
    // this html 'language' depreciated, must be 'type="text/javascript"'
    print "<script language=\"JavaScript\">";
         
    // now is php
          
    function departmentClass()
          {
             for (
    $i=0$i<arguments.length$i++)
             {
               
    // oops, this is js and must be echoed, but 'this' means 'window'?
               
    this[departmentClass.arguments[$i]] = new Array2D(100,100);
               
    // next 2 lines php!
             
    }
          }
          
    // this is js:
          
    function Array2D(dim1dim2)
          {
             
    // this must be php? or some js framework which use $ notation?
             
    for ($i=0$i<dim1; ++$i)
             {
               
    this[$i] = new Array(dim2);
             }
            
    this.length = new Array(dim1,dim2);
          } 
    try to make it clear else will be a nightmare to debug.

    Quote Originally Posted by saxena View Post
    The " at the end of my print statement was causing the error...
    Its actually working even if i don't put any "return" or "if" in the function department().
    how did you test that this work how you expect?

    best regards
    Last edited by oesxyl; 09-08-2008 at 05:44 PM.

  • #12
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now Iam able to view the site when I run it in the browser...before I could see just that error...

    I dint quite get you here..

    "it's not ok what is here. You generate html and javascript using php, the perfect way to don't know when start js and when php: "

    can u please explain it clearly..

    Also VIM helps...its a lot better than vi...
    Thanks.
    Last edited by saxena; 09-08-2008 at 08:00 PM.

  • #13
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you have KDE? I love using Kate as a coding editor.

    It's not the easiest to see what's going on with JS or HTML when you have the PHP echoing or printing it. In my editor at least, it is just all highlighted red. You can simplify this by going out of php mode - anything between the ?> and <?php will be echoed.

    So, it might be easier to tell whats going on with the js if you put in the document out of php mode. Just me suggestion!


  •  

    Posting Permissions

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