Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiple check boxs
#1
i need multiple check boxs from a list of "courses" i have in a mysql database i cant figure this out
Reply
#2
Provide the source where you're expiriencing the problem.
Or do you want an example?
Reply
#3
more of an example

like kinda what im looking for

is

check boxes each one a differnt class wich is in a database (i have the courses in the database)
user registers taken to this page(have that) and
the selected all the courses there in and hit submit it will sign there user_id to the class_id if that makes sense?
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)