Jump to content

Tickbox and database


bamfon

Recommended Posts

I got a text bow shown below,

<input name="category[]" value="Action" type="checkbox">
                  Action </li>
                <li>
                  <input name="category[]" value="Adventure" type="checkbox">
                  Adventure </li>
                <li>
                  <input name="category[]" value="Bishounen" type="checkbox">
                  Bishounen </li>
                <li>
                  <input name="category[]" value="Comedy" type="checkbox">
                  Comedy </li>
                <li>
                  <input name="category[]" value="Demons" type="checkbox">
                  Demons </li>
                <li>
                  <input name="category[]" value="Drama" type="checkbox">
                  Drama </li>
                <li>
                  <input name="category[]" value="Ecchi" type="checkbox">
                  Ecchi </li>
                <li>
                  <input name="category[]" value="Fantasy" type="checkbox">
                  Fantasy </li>
                <li>
                  <input name="category[]" value="Harem" type="checkbox">
                  Harem </li>
                <li>
                  <input name="category[]" value="Horror" type="checkbox">
                  Horror </li>
                <li>
                  <input name="category[]" value="Josei" type="checkbox">
                  Josei </li>
                <li>
                  <input name="category[]" value="Magic" type="checkbox">
                  Magic </li>
                <li>
                  <input name="category[]" value="Mahou Shoujo " type="checkbox">
                  Mahou Shoujo </li>
              </ul></td>
              <td width="34%"><ul>
                <li style="float:none">
                  <input name="category[]" value="Martial Arts" type="checkbox">
                  Martial Arts </li>
                <li>
                  <input name="category[]" value="Mecha" type="checkbox">
                  Mecha </li>
                <li>
                  <input name="category[]" value="16Music" type="checkbox">
                  Music </li>
                <li>
                  <input name="category[]" value="Mystery" type="checkbox">
                  Mystery </li>
                <li>
                  <input name="category[]" value="Ninja" type="checkbox">
                  Ninja </li>
                <li>
                  <input name="category[]" value="Parody" type="checkbox">
                  Parody </li>
                <li>
                  <input name="category[]" value="Psychological" type="checkbox">
                  Psychological </li>
                <li>
                  <input name="category[]" value="Reverse Harem" type="checkbox">
                  Reverse Harem </li>
                <li>
                  <input name="category[]" value="Romance" type="checkbox">
                  Romance </li>
                <li>
                  <input name="category[]" value="Samurai" type="checkbox">
                  Samurai</li>
                <li>
                  <input name="category[]" value="School Life" type="checkbox">
                  School Life </li>
                <li>
                  <input name="category[]" value="Science Fiction" type="checkbox">
                  Science Fiction </li>
                <li>
                  <input name="category[]" value="Seinen" type="checkbox">
                  Seinen </li>
              </ul></td>
              <td width="33%"><ul style=" ">
                <li>
                  <input name="category[]" value="Shoujo" type="checkbox">
                  Shoujo</li>
                <li>
                  <input name="category[]" value="Shoujo Ai" type="checkbox">
                  Shoujo Ai</li>
                <li>
                  <input name="category[]" value="Shounen" type="checkbox">
                  Shounen </li>
                <li>
                  <input name="category[]" value="Shounen Ai" type="checkbox">
                  Shounen Ai </li>
                  <li>
                  <input name="category[]" value="Si-Fi" type="checkbox">
                  Si-Fi </li>
                <li>
                  <input name="category[]" value="Slapstick" type="checkbox">
                  Slapstick </li>
                <li>
                  <input name="category[]" value="Slice of Life" type="checkbox">
                  Slice of Life </li>
                <li>
                  <input name="category[]" value="Sports" type="checkbox">
                  Sports </li>
                <li>
                  <input name="category[]" value="Sucpernatural" type="checkbox">
                Sucpernatural </li>
                <li>
                  <input name="category[]" value="Thriller" type="checkbox">
                  Thriller </li>
                <li>
                  <input name="category[]" value="Tragedy" type="checkbox">
                  Tragedy </li>
                <li>
                  <input name="category[]" value="38" type="checkbox">

 

I know How to save the ticked ones to the database using 

implode(',', $_POST['category'])

 

on the edit page I got the check list again, but I dont know how to go about ticking the once that have been put in the database

Link to comment
Share on other sites

not sure if this is what you want,

<input name="category[]" value="Demons" type="checkbox" checked="checked">

will automatically check it for you.

 

p.s. if you put all possible values in an array, you could rewrite your form in just 4 or 5 lines with a simple foreach() statement.

Link to comment
Share on other sites

not sure if this is what you want,

<input name="category[]" value="Demons" type="checkbox" checked="checked">

will automatically check it for you.

 

p.s. if you put all possible values in an array, you could rewrite your form in just 4 or 5 lines with a simple foreach() statement.

That is not what I wanted did you even read what i said?

 

 

Also whats the point of having a long messy  array when I can do it this way?

Link to comment
Share on other sites

man, that's quite an attitude considering I'm the only person donating my time and knowledge to try and help you so far.

and yes, I did read your post:

on the edit page I got the check list again, but I dont know how to go about ticking the once that have been put in the database

 

this leads me to believe that you want to present the same page again, but with the boxes that got saved in the database already ticked.

So what I answered the first time will do it for you. All that is missing is grabbing the ticked values from the database and comparing with the form element values, then applying the checked="checked" to the desired ones. (this would be one line of code if you used an array)

 

Also there's nothing messy about arrays, it would actually make your code much faster to maintain, and to implement this new feature.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.