update multiple rows another table

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
josecnp1
User
Posts: 73

update multiple rows another table

Post by josecnp1 »

I'm trying this function to insert data into another table taking the values of another.

// Row Inserted event
function Row_Inserted($rsold, &$rsnew) {
$clv = ew_ExecuteScalar("SELECT id_propiedades FROM propiedades WHERE gestor=2 ORDER BY propiedades.id_propiedades ASC");
$estado = ($rsnew["estado"] <> "") ? $rsnew["estado"] : "1";
$cuenta = ($rsnew["cuenta"] <> "") ? $rsnew["cuenta"] : "";

$sInsertSql3 = " INSERT INTO cuotas (clv_cuota ,estado ,cuenta) VALUES ('$clv','$estado','$cuenta')";
$GLOBALS["conn"]->Execute($sInsertSql3);
}

works correctly but I just insert the first value, not all those in $clv
Is there anything that is not doing well?


scs
User
Posts: 694

Post by scs »

Do you know than ew_ExecuteScalar() is to Executes the query, and returns the first column of the first row.

So you have only one record in your existing script.

Please check the HELP file.
ew_Execute() ===> SQL Execute UPDATE, INSERT, or DELETE statements.
ew_ExecuteRow() ===> SQL Executes the query, and returns the first row as an array.
ew_ExecuteScalar() ===> SQL Executes the query, and returns the first column of the first row.

If you need to have multiple records, you need to use ew_Execute(), then do a while condition.


josecnp1
User
Posts: 73

Post by josecnp1 »

I try but I get this error:

Catchable fatal error: Object of class mysqlt_driver_ResultSet could not be converted to string in C:\Web\administracion\cuotagenerarinfo.php on line 1020

try to solve it with this modification but does not give me results

I run out of ideas

// Row Inserted event
function Row_Inserted($rsold, &$rsnew) {
$clv = ew_Execute("SELECT id_propiedades FROM propiedades WHERE gestor=2 ORDER BY propiedades.id_propiedades ASC");
$estado = ($rsnew["estado"] <> "") ? $rsnew["estado"] : "1";
$cuenta = ($rsnew["cuenta"] <> "") ? $rsnew["cuenta"] : "";

foreach($clv as $value){
  
$row_data[] = "('$value','$estado','$cuenta','$concepto','$pendiente','$tipocuota','$formapago','$referencia','$referenciabanco','$fecha','$debe','$haber','$observaciones','$clv_parent','$control_user','$control_ip')";
}

$sInsertSql3 = " INSERT INTO `cuotas` (`clv_cuota` ,`estado` ,`cuenta` ,`concepto` ,`pendiente` ,`tipocuota` ,`formapago`, `referencia` ,`referenciabanco`, `fecha`, `debe` ,`haber` ,`observaciones` ,`clv_parent` ,`control_user` ,`control_ip`) VALUES".implode(',', $row_data);
	
$GLOBALS["conn"]->Execute($sInsertSql3);
}

mobhar
User
Posts: 11753

Post by mobhar »

To get the value by looping from the returned recordset, please try to follow this post: http://www.hkvforums.com/viewtopic.php? ... 81#p105027


Post Reply