This topic is locked
[SOLVED]

 Button to update multiple records

11/25/2010 10:33:53 AM
PHPRunner General questions
ficcionista author

Hi,
i have inserted a button to update selected (multiple) records on the list page just like demonstrated in the Manual, and that button disabled the search function.

Also, the advanced search stops working as well.
Here's what i have:
Key Field (Primary Key) --> matid

function OnServer($params,$result,$keys){

global $dal;

for ($i=0; $i<count($keys);$i++)

{

$sql = "update material set existencia='Instalado', movimento='Saida' where matid=".$keys[$i]["matid"];

CustomQuery($sql);

}

$result["txt"] = "Saida de material efectuada.";

}// function OnServer
function OnAfter(result,ctrl)

{ var message = result["txt"];

ctrl.setMessage(message);

}// function OnAfter


The button was inserted before the Add New Button. Here's the source:

<DIV {$marginStyle} moveForSearch="move{$id}">

{BEGIN recordcontrols_block}

<DIV id="recordcontrols_block{$id}" class=body3>

<INPUT id=Saida_de_Material class=button value="Saida de Material" type=button typeid="ib">

{BEGIN newrecord_controls}

<SPAN id="newrecord_controls{$id}">

{BEGIN add_link}

<SPAN class=buttonborder>

<INPUT class=button value="Add new" type=button {$addlink_attrs}>

</SPAN>

{END add_link}

</SPAN>

{END newrecord_controls}

(...etc...)

{END recordcontrols_block}


When i disable the button, the search starts working again.
thanks.

K
karmacomposer 11/25/2010

For some reason, this code does not work for me at all. I have a nearly identical need for a button to change a field in all selected and I was hopeful your code would do it. It just stays on 'contacting server' the entire time.
Mike

kujox 11/26/2010



For some reason, this code does not work for me at all. I have a nearly identical need for a button to change a field in all selected and I was hopeful your code would do it. It just stays on 'contacting server' the entire time.
Mike


I've added a button for displaying selected records but the principle should be the same, ID is the primary key in my table



### this goes in the OnServer function ###

$result['txt'] = "";

foreach($keys AS $value) {

$result['txt'] .= update_record($value['id']);# this is a function i've wrote, included in after app initialised but you can put any code here.

$result['txt'] .= "Record " . $value['id'] . " updated
";

}
### this is in the OnAfter function ###

var message = result["txt"] + "
Completed";

ctrl.setMessage(message);


I did get a problem on the connecting to server message been displayed all the time but this was due to an error caused by a incorrect variable name in the OnBefore function

kujox 11/26/2010



I've added a button for displaying selected records but the principle should be the same, ID is the primary key in my table



### this goes in the OnServer function ###

$result['txt'] = "";

foreach($keys AS $value) {

$result['txt'] .= update_record($value['id']);# this is a function i've wrote, included in after app initialised but you can put any code here.

$result['txt'] .= "Record " . $value['id'] . " updated
";

}
### this is in the OnAfter function ###

var message = result["txt"] + "
Completed";

ctrl.setMessage(message);


I did get a problem on the connecting to server message been displayed all the time but this was due to an error caused by a incorrect variable name in the OnBefore function



Mike,
If you want to try this.



### this goes in the OnServer function ###

$result['txt'] = "";

foreach($keys AS $value) {

$sql = "update material set existencia='Instalado', movimento='Saida' where matid=".$value["matid"];

CustomQuery($sql);

$result['txt'] .= "Record " . $value['matid'] . " updated
";

}
### this is in the OnAfter function just for the updated message ###

var message = result["txt"] + "
Completed";

ctrl.setMessage(message);



Hope this works for you.

ficcionista author 12/6/2010

Ok, I found out what wasn't working for me.
It seems that adding a button will mess up the search function, but only if you set it to "Show basic search options..."

I disabled this option and changed it to "Show search panel" and the butto worked fine without losing the ability tot search.