...

View Full Version : PHP Programming



saxena
09-05-2008, 09:39 PM
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.

abduraooft
09-06-2008, 07:13 AM
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
][/b] tags to enhance the readability.

saxena
09-07-2008, 06:05 AM
I am doing it in vi editor on LINUX.



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.

oesxyl
09-07-2008, 07:28 AM
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.


I am doing it in vi editor on LINUX.



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:


$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:


$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

julian
09-08-2008, 02:15 AM
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.

oesxyl
09-08-2008, 03:45 PM
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

saxena
09-08-2008, 04:05 PM
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:




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);
}";


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.

saxena
09-08-2008, 04:10 PM
and...

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

oesxyl
09-08-2008, 04:30 PM
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:


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);
}";




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

saxena
09-08-2008, 05:06 PM
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!!!

oesxyl
09-08-2008, 05:42 PM
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:


// 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(dim1, dim2)
{
// 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.


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

saxena
09-08-2008, 07:57 PM
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.

julian
09-08-2008, 08:30 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum