Jump to content

the_mossman

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

the_mossman's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have a db that stores id and size for checked checkboxes. (Only checked checkboxes i stored in this db) I want to generate checkboxes until $i<(a specified number). If the value of the checkbox that is about to be created is already stored in the db, then make the checkbox that is created CHECKED. IN SHORT: Create the checkboxes with the value that are not stored in the DB unchecked. If the checkbox value is stored in the DB, create the checkbox checked. $query = "SELECT * FROM db WHERE fileid=$fileid"; $result = mysql_query($query,$db_link); $rows = mysql_num_rows($result); $a = 4.5; //Value of the first checkbox generated echo "<form method =\"post\" action=\"sizes.php\">"; for ($i=0; $i<20; $i++){ $a = $a + 0.5; //size is increased by 0.5 for each checkbox for($x=0; $x<$rows; $x++) { $size = mysql_result($result,$x,"size"); //size is retreived from db where fileid=$fileid if ($a == $size) { //Here I want to say: if there is a value in db, display teh box as checked echo "<input name=\"sizes[]\" type=\"checkbox\" value=\"$a\" checked=\"checked\" />$a "; $a = $a + 0.5; } } echo "<input name=\"sizes[]\" type=\"checkbox\" value=\"$a\" />$a "; //every box that is not checked } echo "<input type=\"hidden\" name=\"fileid\" value=\"$fileid\">"; echo "<input type=\"submit\" name=\"submit\" value=\"Ok\" style=\"width: echo "</form>"; $submit = $_POST['submit']; if ($submit == "Ok"){ $mySizes = $_POST['sizes']; $fileid = $_POST['fileid']; $query = "DELETE FROM greppet_sizes WHERE fileid='$fileid'"; mysql_query($query,$db_link); if ($mySizes != null){ foreach ($mySizes as $value){ $query = "INSERT INTO greppet_sizes VALUES (null,$fileid,'$value')"; mysql_query($query,$db_link); } } } 100px;\" />
×
×
  • 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.