解析错误:语法错误,意外T_ENCAPSED_AND WHITESPACE,期待T_STRING [英] Parse error: syntax error, unexpected T_ENCAPSED_AND WHITESPACE, expecting T_STRING
问题描述
我的大师和天使 -
请原谅这位老派程序员,最近才开悟到开源,被困在专有语言的便利中太长时间了。我的缺点很快就会变得明显。
我正在开发一个估算构造系统,使用PHP5和MySQL 5.0.24a和Ubuntu。我有一个主要的项目文件和2个详细文件,一个用于管道,一个用于设备。这些文件中的每一个每个项目都有多个条目,并且我在每个项目中都有出价项目的进一步细分。和系统/线路。对于报告,投标项目可能包含管道或设备,或两者兼而有。
要计算出价,我会浏览详细文件并计算小计。文件,进一步向下报告。我在每次运行开始时重新启动这个小计文件。
我的问题开始于管道 - 设备来得更晚。我需要循环遍历各个行并处理一些数字。如果当前出价项目/行#combo存在现有的小计记录,我们将添加该记录。如果没有,我们将开始一个 - 通过选择的返回值使操作变得更复杂。而不是插入。
这是我的麻烦代码的简化版本:
[PHP] $ presult = mysql_query (select * from mrb_pipe
其中pproj =''$ proj''");
while($ pipe = mysql_fetch_assoc($ presult)){<
$ tpbidit = $ pipe [" pbidit"];
$ tpsys = $ pipe [" psys"];
$ stresult = mysql_query {" select * from mrb_stot
where sbidit =''$ tpbidit''// select不喜欢下标
和ssys =''$ tpsys'' "); //参数,所以我发了$ vars
if(mysql_num_rows($ stresult)<> 1){
mysql_query(" insert into mrb_stot .... )//加载一个新行
或死(bummer);
$ stresult = mysql_query(" select * from mrb_stot
其中sbidit =''$ tpbidit''
和ssys =''$ tpsys''"); //将结果加载到$ stresult
)
$ subt = mysql_fetch_assoc($ stresult);
$ mysql_free_result($ stresult);
getSurf(1,$ pipe [" psize"],$ pipe [" pthk"]); //功能还包括
// mysql_query
$ actstr = $ pipe [" pstr"]; //初始化
$ strbdsf = $ actstr * $ psfmlt; // $ psfmlt由getSurf func返回
$ winssf = $ subt [" inssf"]; //将添加到这个工作变量[/ PHP]
此时我得到一个Parse错误:语法错误,意外T_ENCAPSED
_AND WHITESPACE,期待T_STRING ......错误,在最后一行。
我对我的语法感到厌烦,但无济于事。这条线实际上与前一条线相同,显然工作正常。我必须得出结论,第二个结果集存在问题。我在使用数学计算中的下标变量时遇到了问题,但可以先通过转换为常规$变量来避免这些变量。
我已经搜索了许多嵌套查询问题,但它们似乎总是与同一select语句中的嵌套查询有关。要么我的应用程序非常不寻常 - 我认为它相当简单,不需要复杂的外连接 - 和/或我在理解MySQL存储方式方面有一些严重的缺点。很可能是后者。
我希望我已经包含了足够的细节,有人可能会抓住我的问题的本质,并建议一个更好的方法来剥皮这只猫!我最后一次呼吁这个论坛,我对解决方案感到尴尬 - 我应该先尝试一下!!我希望这次不是这样的。
任何提示都会非常感激! - Estimator'的好友
My Gurus and Angels --
Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My shortcomings will soon become apparent.
I am developing an estimating construction system, using PHP5 and MySQL 5.0.24a with Ubuntu. I have a main "projects" file, and 2 detail files, one for piping and one for equipment. Each of these files will have multiple entries per project, and I have further breakdowns in each, by "bid item" and "system/line." For reporting, a bid item may contain piping, or equipment, or both.
To calculate the bid, I spin through the detail files and calculate a "subtotals" file, which is reported further down the line. I restart this subtotals file at the start of each run.
My problems begin in piping -- equipment to come later. I need to cycle through the individual rows and crunch some numbers. If there is an existing subtotals record for the current bid item/line # combo, we will add to it. If not, we will start one -- an operation made more complicated by the return values of "select" as opposed to "insert."
Here is a simplified version of my troubled code:
[PHP]$presult = mysql_query("select * from mrb_pipe
where pproj = ''$proj''");
while ($pipe = mysql_fetch_assoc($presult)) {
$tpbidit = $pipe["pbidit"];
$tpsys = $pipe["psys"];
$stresult = mysql_query{"select * from mrb_stot
where sbidit = ''$tpbidit'' // select didn''t like subscripted
and ssys = ''$tpsys''"); // arguments, so i made $vars
if (mysql_num_rows($stresult) <> 1) {
mysql_query("insert into mrb_stot ....) // load a new row
or die("bummer");
$stresult = mysql_query("select * from mrb_stot
where sbidit = ''$tpbidit''
and ssys = ''$tpsys''"); // load result into $stresult
)
$subt = mysql_fetch_assoc($stresult);
$mysql_free_result($stresult);
getSurf(1, $pipe["psize"], $pipe["pthk"]); // function also includes
// mysql_query
$actstr = $pipe["pstr"]; // initialize
$strbdsf = $actstr * $psfmlt; // $psfmlt returned by getSurf func
$winssf = $subt["inssf"]; // will add to this work variable[/PHP]
At this point I get a Parse error: syntax error, unexpected T_ENCAPSED
_AND WHITESPACE, expecting T_STRING ... error, on the last line.
I have pored over my syntax, to no avail. This line is virtually identical to the one which occurs 2 previous, and apparently works fine. I have to conclude that there is a problem with the second result set. I also had a problem using subscripted variables in math calculations, but could avert those by converting to regular $variables first.
I have Googled many nested-query problems, but they always seem to relate to nested queries within the same select statement. Either my application is very unusual -- and I had thought it fairly simple, in need of no complex outer joins -- and/or I have some serious shortcomings in my understanding of how MySQL stores things. Most likely the latter.
I hope I have included enough detail, that someone may grasp the essence of my issues, and suggest a better way to skin this cat!! The last time I appealed to this forum, I was embarrassed at the solution -- I should''ve tried that first!! I hope that is not the case this time.
Any hints at all would be greatly appreciated! -- The Estimator''s Buddy
推荐答案
presult = mysql_query(" select * from mrb_pipe
其中pproj =''
presult = mysql_query("select * from mrb_pipe
where pproj = ''
proj''");
while(
proj''");
while (
pipe = mysql_fetch_assoc(
pipe = mysql_fetch_assoc(
这篇关于解析错误:语法错误,意外T_ENCAPSED_AND WHITESPACE,期待T_STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!