How to Multi-select several rows and insert them into another table and set common values

QuestionsHow to Multi-select several rows and insert them into another table and set common values
Alphonse asked 2 months ago

Hello Abu please help.

I have a table (courses) with a list of all courses done for a specific diploma program, I have another table called courses_on_offer, my aim is to get/select several courses from table (courses) and click a button (Add Courses) to insert all selected courses into another table (courses_on_offer) and set common values for inserted rows which include session_id, start_date, end_date.

I tried with excel blank rows

function update_data($data)
{
$grid = new jqgrid();
// If bulk operation is requested, (add-rows default otherwise)
if ($data[“params”][“bulk”] == “add-rows”)
{
for($i=0;$i<$rows;$i++)
$grid->execute_query(“INSERT INTO courses_on_offer (id,course_code,course_name) VALUES (”,'{$data[“params”][“course_code”]}’,'{$data[“params”][“course_name”]}’)”);
die;
}

course_code and course_name are blank when I try the code above

Please help me.

2 Answers
Abu Ghufran Staff answered 2 months ago

I’d suggest to use different approach. Refer bulk edit demos/editing/bulk-edit.php

Select row and perform bulk operation, like in demo (email rows) or similar. And in callback, you will receive IDs of the selected rows of course table.

There you can runĀ $grid->execute_query for INSERT INTO table SELECT query.

INSERT INTO table2 (column1, column2, column3, …)
SELECT column1, column2, column3, …
FROM table1

You can use common values in sql as well as fixed string.

_________________________
Abu Ghufran - Dev Team
PHP Grid Framework
 
Alphonse answered 2 months ago

Thank you Abu. Above solution worked perfectly.

Again Thanks a bunch.

Your Answer

11 + 9 =

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 / 5. Vote count:

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

Let us improve this post!