Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiple check boxs
#4
Not knowing your database structure it'd be hard to give accurate queries but this is what I'd do:

PHP Code:
<?php
echo "<form method=\"post\" action=\"\">\n";
$query mysqli_query($link"SELECT * FROM `courses`;");
while(
$course mysqli_fetch_assoc($query))
{
    echo 
"<input type=\"checkbox\" name=\"courses[]\" id=\"{$course['name']}\" value=\"{$course['id']}\"> <label for=\"{$course['name']}\">{$course['name']}</label>\n";
}
echo 
"</form>\n";
if(
$_POST['courses'])
{
    
$list_of_courses "";
    foreach(
$_POST['courses'] as $course)
    {
        
$course htmlspecialchars($course);
        
$list_of_courses[] = $course;
    }
    
$new_list_of_courses implode("|"$list_of_courses);
    
$update mysqli_query($link"UPDATE `users` SET `courses` = '{$new_list_of_courses}' WHERE `user` = '{$whatever}';");
}
?>

Then you'd get something like 1|2|4|8|16 as a list of courses associated to each use, that's how I'd arrange it.
MyBB Support Team Lead
Reply


Messages In This Thread
multiple check boxs - by Darkside92 - 12-15-2009, 03:52 PM
RE: multiple check boxs - by Gaijin - 12-15-2009, 04:19 PM
RE: multiple check boxs - by Darkside92 - 12-15-2009, 06:16 PM
RE: multiple check boxs - by MattR - 12-16-2009, 01:22 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)