INSERT SELECT query and combine values from add record dialog form

QuestionsINSERT SELECT query and combine values from add record dialog form
Alphonse asked 5 years ago

Hello Abu, I trust you are well as it is the case with me, please help me on this I have tried severally

My aim is to have a Toolbar Button or Custom Button, When user clicks on it and there is no selected row or rows, it displays a message you need to select a row/rows, if the user has selected row/rows, it displays add record dialog form, where the user must enter some values, in this case (Offer Status, Effective Date, Closing Date), on Submit button, the values of the form are passed to the INSERT SELECT query. This is part of what I have in code

***************************************************************************************************************************

// virtual column to enter user data (Required*)
$col = array();
$col[“title”] = “Offer Status”;
$col[“name”] = “offer_status”;
$col[“width”] = “50”;
$col[“editable”] = true;
$col[“editoptions”] = array(“value”=>”1:0”); // with these values “checked_value:unchecked_value”
$cols[] = $col;

$col = array();
$col[“title”] = “Effective Date”;
$col[“name”] = “effective_date”;
$col[“formatter”] = “date”;
$col[“editrules”] = array(“required”=>true);
$col[“width”] = “50”;
$col[“editable”] = true;
$cols[] = $col;

$col = array();
$col[“title”] = “Closing Date”;
$col[“name”] = “closing_date”;
$col[“formatter”] = “date”;
$col[“editrules”] = array(“required”=>true);
$col[“width”] = “50”;
$col[“editable”] = true;
$cols[] = $col;

**************************************************************************************************************************

$e[“on_update”] = array(“update_data”,””,false);

function update_data($data)
{
// temp grid object to execute sql
$g = new jqgrid();

else if ($data[“params”][“bulk”] == “add-courses-on-offer”)
{

$selected_ids = $data[“id”]; // e.g. the selected values from grid 5,7,14 (where “id” is field name of first col)
$offer_status = $data[“params”][“offer_status”];
$effective_date = $data[“params”][“effective_date”];
$closing_date = $data[“params”][“effective_date”];

$g->execute_query(“INSERT INTO courses_on_offer (session_id,course_code,offer_status,effective_date,closing_date) SELECT s.session_id, c.course_code, ‘$offer_status’, ‘$effective_date’, ‘$closing_date’ FROM sessions s CROSS JOIN programme_courses c WHERE c.id IN ($selected_ids)”);

die;
}

}

**********************************************************************************************************************

jQuery(‘#list1’).jqGrid(‘navButtonAdd’, ‘#list1_pager’,
{
‘caption’ : ‘Add courses’,
‘buttonicon’ : ‘ui-icon-plus’,
‘onClickButton’: function()
{
var opts = jQuery(‘#add_list1’).click();
if (opts)
fx_bulk_update(“add-courses-on-offer”);
},
‘position’: ‘last’
});

**************************************************************************************************************************

The above adds the selected values first, then displays add record dialog form, on submit it adds a record with values on the form, I want to combine selected values on the grid with the values on the add record form when you click on submit button

Kindest Regards

 

5 Answers
Abu Ghufran Staff answered 5 years ago

If i understand your question correctly,

If you make it 3rd param to false, then it should return json data
// e.g. $e[“on_insert”] = array(“add_client”, null, false);

$insert_id = $grid->execute_query($sql,false,”insert_id”);

if (intval($insert_id)>0)
$res = array(“id” => $insert_id, “success” => true);
else
$res = array(“id” => 0, “success” => false);

echo json_encode($res);
die;

It will the close the dialog and refresh grid as well.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Abu Ghufran Staff answered 5 years ago

Your code seems fine, it should do what you are asking. What issue are you facing running this code. You can debug inside callback function by:

function update_data($data)
{
phpgrid_error($data);


}

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Alphonse answered 5 years ago
  1. Hi Abu, I’m still not getting the desired results. The selected values on the grid are inserted first, then add record dialog form appears, when I enter values and then click submit, those values are inserted. I want to combine values selected on the grid together with the values on the add record dialog form.
  2. I would also want to add a Dropdown list on the toolbar, which represents a column from the grid that fetches dropdown values from a database.
  3. Finally, I want to add a Dropdown list on the toolbar, which populates dropdown values from a database table field.

Thanks in advance, I hope you will be able to help me as soon as possible.

 

Abu Ghufran Staff answered 5 years ago

I am still unable to to understand your issue. Can you explain more with screenshots of what you need.

Thanks.

PS: Attach screenshot here and paste link in question.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Alphonse answered 5 years ago

Hello Abu, I hope you got the screenshot.

Rgds

Your Answer

1 + 18 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?