rilana Posted January 25, 2009 Share Posted January 25, 2009 Hi guyes I am having a mysql query like this $stelleID = $_GET["stelleID"]; $sqlR = "SELECT * FROM stelle_region WHERE stelleID=$stelleID"; $resultR = mysql_query($sqlR,$con); echo "Folgende Regionen sind diesem Job in der Datenbank zugeteilt:"; echo "<br>"; while($row = mysql_fetch_array($resultR)) { $stelleID=($row['stelleID']); echo ($row['regionID']); echo "<br>"; } ?> this will give me a value 5 and 6. But now I would like to have does values allready checked in my checkboxes.... so people in the backend can see which once are allready in the database and then change them if they want to. <input type="checkbox" name="region[]" value="2" />Rechtes Zürichseeufer<br /> <input type="checkbox" name="region[]" value="6" />Graubünden<br /> <input type="checkbox" name="region[]" value="5" />Zürich<br /> <input type="checkbox" name="region[]" value="1" />Linkes Zürichseeufer<br /> <input type="checkbox" name="region[]" value="3" />Glarus<br /> <input type="checkbox" name="region[]" value="4" />Zürich Oberland<br /> Is there a way to do this? I would aprechiate any help. Thank you verry much! Rilana Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted January 25, 2009 Share Posted January 25, 2009 you can use an if statement inside the <input> and check those that needs to be.. something like this <input type="checkbox" name="region[]" value="2" <?php if (this should be checked) { echo "checked"; } ?> /> Quote Link to comment Share on other sites More sharing options...
rilana Posted January 29, 2009 Author Share Posted January 29, 2009 Thank you for your replay. I tryed several things now and came up with this code: $sqlR = "SELECT * FROM stelle_region WHERE stelleID=$stelleID"; $resultR = mysql_query($sqlR,$con); while($row = mysql_fetch_array($resultR)) { $region=($row['regionID']); print_r ($region); if($region == "1") { echo "<input type='checkbox' name='region[]' value='1' echo'CHECKED'/>Linkes Zürichseeufer<br />"; } if($region == "2") { echo "<input type='checkbox' name='region[]' value='2' echo'CHECKED'/>Rechtes Zürichseeufer<br />"; } if($region == "3") { echo "<input type='checkbox' name='region[]' value='3' echo'CHECKED'/>Glarus<br />"; } } this works fine but there is one big Problem I am having. I also need to show the checkboxes which dont have a entry in the database so it's possible to check them in edit mode. I tryed to do it like this: if($region == "1") { echo "<input type='checkbox' name='region[]' value='1' echo'CHECKED'/>Linkes Zürichseeufer<br />"; } else { echo "<input type='checkbox' name='region[]' value='1' >Linkes Zürichseeufer<br />"; { the problem with that is the while function I think, because if I have 2 entrys or more in multiplys my checkboxes.... What can I do to show all the checkboxes that are possible without multiplying them and checking the right once? Thank you so much for your Help! I am going grazy over this! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.