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("se lect * from mrb_pipe
where pproj = '$proj'");
while ($pipe = mysql_fetch_ass oc($presult)) {
$tpbidit = $pipe["pbidit"];
$tpsys = $pipe["psys"];
$stresult = mysql_query{"se lect * 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("in sert into mrb_stot ....) // load a new row
or die("bummer");
$stresult = mysql_query("se lect * from mrb_stot
where sbidit = '$tpbidit'
and ssys = '$tpsys'"); // load result into $stresult
)
$subt = mysql_fetch_ass oc($stresult);
$mysql_free_res ult($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
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("se lect * from mrb_pipe
where pproj = '$proj'");
while ($pipe = mysql_fetch_ass oc($presult)) {
$tpbidit = $pipe["pbidit"];
$tpsys = $pipe["psys"];
$stresult = mysql_query{"se lect * 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("in sert into mrb_stot ....) // load a new row
or die("bummer");
$stresult = mysql_query("se lect * from mrb_stot
where sbidit = '$tpbidit'
and ssys = '$tpsys'"); // load result into $stresult
)
$subt = mysql_fetch_ass oc($stresult);
$mysql_free_res ult($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
Comment