Hi i currently have the following code

if($line["areas"] == 'i'){echo ' checked="checked"';}  

at the minute it checks to see if the value "i" is present in the db and if so it checks the check box HOWEVER it only checks the check box if the only value s "i", i have multiple values in the field. If i remove an "=" from the code it checks the box no matter what value is present.

Does anyone know how to check if the value "i" is present no matter what else is in the box. I have tried explode() but cannot query the array it still has the same result.

PLEASE HELP!!!, Thank you in advance🙂

    Hi,

    This wiil check if 'i'is inside the string

    if(strpos($line["areas"], 'i') >= 0){echo ' checked="checked"';}

      I tried that and it just checked the box no matter what again, surely i must be making a mistake some where else??

        Ok, but if $line["areas"] has an 'i' it will check

        are you sure there are cases without an 'i' ?

          IT WORKED lol

          <input type="checkbox" name="media[]" value="i" <?php if(strpos($line["areas"], 'i') >= $i){echo ' checked="checked"';}?> />i<br />

          I just set variable $i=i so if $i's value is present in the databse then check the box.

          THANK YOU!!!!

          Tried for ages on other forum no help come here you sort it straight away lol

            Well... however that doesnt seem to be the solution... I think you need to understand what you just write

            anyway... post back here if you need more help

              I DONT UNDERSTAND LOL

              With this

              <input type="checkbox" name="media[]" value="i" <?php if(strpos($line["areas"], 'i) >= 0){echo ' checked="checked"';}?> />i<br />

              It checks it no matter what

              but with this

              <input type="checkbox" name="media[]" value="i" <?php if(strpos($line["areas"], 'i) >= #$i){echo ' checked="checked"';}?> />i<br />

              it works fine however it seems to check other boxes lol, for instance if i had one calle EC it would check one called E.

                Yeah, i was expecting something would go wrong...

                So can you give me some examples of:

                $line["areas"]

                and also, if one should be checked or not.

                  For one, both code snippets you posted contain PHP parse errors, so I'm not even sure what it is you're trying... but I can tell it probably won't work.

                  Read the manual page for [man]strpos/man. Look at what the function's purpose is and value it will return.

                    Sorry i will explain what it is i' am trying to do.

                    I have a members area that each member can edit their "areas" the areas being locations throughout the UK. There are around 40 locations and i thought the best way to do it would be check boxes so the member can easily update their locations by simply selecting or De-selecting the check box. After they have chose the locations they wish it updates the database and then in the members area it checks the check boxes depending on the locations they selected.

                    sorry if this is a bit hazy.

                    The kind of items in the db will be the location id = LU, SR, DH etc. separated by a comma.

                      I would need to see how your database is build, but I noticed that you named the checkboxes as media[], which tell php that media is an array.

                      You could use serialise() function to store the information. Later on you just compare keys from the arrays, and if they match you check the box. That's the approach I choosed on one of my projects with online test with checkboxes and radios, and it worked like a dream.

                        Write a Reply...