Below is the script i am using to show the list of checkboxes for the user to choose from. When they make their selection i want to take the ones they chose and list them using a comma between the chosen so i can add them to the database into one value. I don't know if i have to use a string or how to even begin.

	//CHECKBOX SELECTION
	$sql5 = "SELECT * FROM nuke_worship_inv_list";
	$result5 = $db->sql_query($sql5);

while($row = $db->sql_fetchrow($result5)) { 
        			$category = $row['category'];
        			echo " <input type=\"checkbox\" name=\"user_inv_worship\" value=\"$category\">:$category";
			echo "<br>";
 			 } 

    This is a very bad idea. Set up your database with a different field for each checkbox. You'll thank me later.

      Originally posted by nemonoman
      This is a very bad idea. Set up your database with a different field for each checkbox. You'll thank me later.

      Errr.... before you do this (and it is better than using a comma-delimited list): do you know how many checkboxes there are going to be? Might that number change in the future? If so, what you'll want is a separate table listing all the possible checkboxes, with an ID number for each one, and another table to link it to the table where you're currently thinking of putting the list.

      user | checkbox_id
      -----+------------
      1   | 1
      1   | 2
      2   | 1
      2   | 4
      

      Says that user 1 has selected boxes 1 and 2, and user 2 has selected boxes 1 and 4.

      id | checkbox_value
      ---+---------------
      1  | something
      2  | something else...
      

      (Is this nuke_worship_inv_list? If so, you're halfway there already).

      PS: More on the subject here

        i have a table with user info on it and i have a table that has the checkboxes on it. you want me to make another table and use for columns the checkbox id and the user id? in the table to gave an example of wont i double up on a lot of info? also will that allow me to delete a box from the users name that maybe they had checked before? I'm new to this and i need alot of help.

        Thankyou for you reply's already if you can explain this to me alittle bit or if you know of a web site, anything would help i'm a pretty quick learner so anything would do/

          Originally posted by Skeelo
          i have a table with user info on it and i have a table that has the checkboxes on it. you want me to make another table and use for columns the checkbox id and the user id?

          Yes; when you're keeping data specific to the user in one table, and data specific to the checkboxes in another table, you need some way of relating the two. Especially in a relational database.

          wont i double up on a lot of info?

          No, you'll actually be avoiding "doubling up" info.

          Thankyou for you reply's already if you can explain this to me alittle bit or if you know of a web site, anything would help i'm a pretty quick learner so anything would do/

          Google for "Database normalization" - that's what the concept we're talking about is called; there are plenty of tutorials about, including some on this site.

            thank you again for your response. I have only had 1 hr of sleep in the last two days trying to get this working hopefully now i can fix it. Thanks

              I had a thought at how you could accomplish this. It's with something called bit stuffing. The process is far to detailed to explain in a message board post so I'm attaching an article I wrote on the topic. Warning this article has not been proread so there are probably gramatical errors in it, but the code snippets have been tested and they do work.

              Enjoy

                Write a Reply...