Jump to content

dynamicaly checked check boxes from mysql values


rilana

Recommended Posts

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

Link to comment
Share on other sites

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....

 

multi.gif

 

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!

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.