This topic is locked

multiple line update with one value

1/21/2008 4:42:01 PM
PHPRunner General questions
H
horsey_kim author

Can someone head me in the right direction.
I currently have an invoice number that shows up from when I add invoice to system. So after you create invoice it goes to a page that shows all the items available for adding to the invoice. Right now you have to row edit for every item you want and make the invoice id of the line as the same of the one you just created and it takes forever.
What I want to do is this: Since I already have the invoice number - which is $_REQUEST["masterkey1"]
How would I get it where the user could just click the select boxes that are there and then click one button or link so that it would take the $request["masterkey1"] and update the line record with the number for each one of the selected lines.
I hope this makes sense?
Kim

J
Jane 1/22/2008

Kim,
you can do the following:

  1. proceed to the "Visual Editor" tab


  2. turn on "HTML mode", find this line:

    <!-- delete form -->

    and add following code just before:

    <A onclick="if (!confirm('Do you really want to update these records?')) return false; frmAdmin.a.value='update'; frmAdmin.submit(); return false;"

    href="TableName_list.htm#">update selected</A>


  3. proceed to the Events tab and add BeforeDelete event.

    Here is a sample code:

    //delete records

    if(@$_POST["a"]=="delete")

    return true;
    //update selected records

    global $conn;

    $strSQL="update Tablename set Fieldname='your value'";

    db_exec($strSQL,$conn);

    return false;



H
horsey_kim author 1/22/2008

Thank you Jane,
But still a problem, It is changing ALL the records in the database table, not just the ones I select. I wanted it to just change the fields of the records I select using the check box on the list page and only those records.
I hope that makes sense.
I put this code in the event BEFORE RECORD DELETED
//delete records

if(@$_POST["a"]=="delete")

return true;
//update selected records

global $conn;

$strSQL="update _seeddata set blueid2='2'";

db_exec($strSQL,$conn);

return false;
In the Code of the page before <!--delete form--> I inserted this code:
<A onclick="if (!confirm('Do you really want to update these records?')) return false; frmAdmin.a.value='update'; frmAdmin.submit(); return false;"

href="pickblue_list.htm#">Add to Invoice</A>

J
Jane 1/23/2008

Kim,
sorry for my fault.

You need to add where clause to your query:

...

$strSQL="update Tablename set Fieldname='your value' where (".$where.")";

...

H
horsey_kim author 1/28/2008

Forgive me but what would be my where clause for the check boxes that you guys already have listed on the list page?
I don't know if this makes sense:
I am not telling the program to do this when a database field match some value. I am asking that when the user selects records from a list of records on the LIST page. to only change the value of the selected.
The way they select the desired records to change, is by checking the check boxes that you guys have already provided on the LIST page for other features such as print selected, delete selected.
I hope this makes sense. I am really new to php and I appologize for my lack of understanding.
Kim

J
Jane 1/28/2008

Kim,
ID of checked values on the list page are stored in the $where variable in the BeforeDelete event.

H
horsey_kim author 2/7/2008

Kim,

ID of checked values on the list page are stored in the $where variable in the BeforeDelete event.


Thank You!!