This topic is locked

Before edit event code syntax

6/27/2007 3:57:09 AM
PHPRunner General questions
jwoker author

I can't seem to get the following code to work in an event. The foreach loop only runs once even though the array should have 8 name/value pairs in it. then when I create a message from within the loop to test it, I get 7 as the value of $orders["id"] when it should be a value between 765 and 773 . any comments or help would be greatly appreciated.

if ($values["otype"]=="Roof"){

$strSQLselect = "select id from job_orders where job_id = '".$values["job_id"]."' and completed < '1'";

$rsMan = db_query($strSQLselect,$conn);

$order=db_fetch_array($rsMan);
foreach ($order as $orders) {

$sql = "UPDATE job_orders SET showit = '0' WHERE id = '".$orders["id"]."'";

db_exec($sql,$conn);

}

}
Alexey admin 6/27/2007

Hi,
foreach won't help here.

Here is the correct code:

if ($values["otype"]=="Roof"){

$strSQLselect = "select id from job_orders where job_id = '".$values["job_id"]."' and completed < '1'";

$rsMan = db_query($strSQLselect,$conn);
while($order=db_fetch_array($rsMan))

{

$sql = "UPDATE job_orders SET showit = '0' WHERE id = '".$order["id"]."'";

db_exec($sql,$conn);

}

}