The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert multiple from input checkbox
#3
I'm going to be writing a class to teach people how to do this, but I can give you the basics.
So there are two tricks with this.

1. Write a query that takes the id of the task and finds all the existing info on that task...

So when you're loading the page you want
(I'm assuming the task_id is a $_Get variable in the URL)
Code:
$task_id = Input::get('id');
Code:
$tasksQ = $db->query("SELECT * FROM tasks WHERE task_id = ?",array($task_id));
Code:
$tasks = $tasksQ->results();

2. Create your form like you did, but on each checkbox, have the db check to see if that box is assigned. (I can't see your code to know how you did this. Essentially what you want to do is to pass the id (NOT task_id) into the form and whether or not you want the box to be checked.

How do you know if you want the box checked? You need to write a function that does the db query and if it should be checked, it returns checked. The input should look like...
Code:
<input type="checkbox" id="employee" name="employee[]" value='<?=$v1->id?>'
Code:
<?php checkTask($v1->id,$id); ?> ><?=$v1->fname." "; ?>
checkTask is what I called your function that queries the db and looks for what should be checked. I'll show you an example of my checkDuty function that queries a different db table....

Code:
function checkDuty($employee,$workorder){
Code:
$db = DB::getInstance();
Code:
$q=$db->query("SELECT id FROM employee_jobs WHERE employee = ? AND workorder = ?",array($employee,$workorder));
Code:
$c=$q->count();

Code:
if($c==1){
Code:
echo "checked='checked'";
Code:
}else{
Code:
return false;
Code:
}
Code:
}

Then, once the form is all done, you need to check the boxes that were checked in the form and uncheck the ones that weren't. My feeling is that it is easiest to just write every single box over again as opposed to only the ones that changed.
  Reply


Messages In This Thread
Insert multiple from input checkbox - by picassoo - 12-20-2016, 07:57 PM
Insert multiple from input checkbox - by picassoo - 12-20-2016, 08:15 PM
Insert multiple from input checkbox - by mudmin - 12-21-2016, 03:00 PM
Insert multiple from input checkbox - by picassoo - 12-21-2016, 06:06 PM
Insert multiple from input checkbox - by picassoo - 12-21-2016, 06:16 PM
Insert multiple from input checkbox - by picassoo - 12-21-2016, 06:44 PM
Insert multiple from input checkbox - by mudmin - 12-21-2016, 08:26 PM
Insert multiple from input checkbox - by picassoo - 12-21-2016, 10:09 PM
Insert multiple from input checkbox - by mudmin - 12-22-2016, 02:03 PM
Insert multiple from input checkbox - by picassoo - 12-22-2016, 08:49 PM
Insert multiple from input checkbox - by mudmin - 12-22-2016, 10:20 PM
Insert multiple from input checkbox - by picassoo - 12-23-2016, 09:47 AM
Insert multiple from input checkbox - by mudmin - 12-23-2016, 01:47 PM
Insert multiple from input checkbox - by picassoo - 12-23-2016, 10:52 PM
Insert multiple from input checkbox - by mudmin - 12-23-2016, 11:10 PM
Insert multiple from input checkbox - by mudmin - 12-23-2016, 11:12 PM
Insert multiple from input checkbox - by picassoo - 12-24-2016, 11:46 AM
Insert multiple from input checkbox - by picassoo - 12-24-2016, 11:48 AM
Insert multiple from input checkbox - by mudmin - 12-24-2016, 04:05 PM
Insert multiple from input checkbox - by picassoo - 12-24-2016, 08:25 PM
Insert multiple from input checkbox - by picassoo - 12-24-2016, 09:16 PM
Insert multiple from input checkbox - by mudmin - 12-25-2016, 07:35 PM
Insert multiple from input checkbox - by mudmin - 12-25-2016, 08:35 PM
Insert multiple from input checkbox - by picassoo - 12-26-2016, 06:54 PM
Insert multiple from input checkbox - by dan - 12-26-2016, 07:16 PM
Insert multiple from input checkbox - by picassoo - 12-26-2016, 08:07 PM
Insert multiple from input checkbox - by dan - 12-26-2016, 09:55 PM
Insert multiple from input checkbox - by picassoo - 12-27-2016, 05:52 AM
Insert multiple from input checkbox - by dan - 12-27-2016, 06:07 AM
Insert multiple from input checkbox - by picassoo - 02-10-2017, 09:53 PM
Insert multiple from input checkbox - by mudmin - 02-11-2017, 02:47 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)