phpaddict
phpaddict

Reputation:

Selecting values from the database and make the checkbox checked if it does exist

//query to check if part id number exists in table ATTEND where service id = ...
$result2 = mysql_query("SELECT * FROM attend WHERE SIDno='$SIDno' and ServiceID='$id");
//if exists $ok = true;
  if (mysql_num_rows($result2)>0) {
        $ok == true;
  }
  echo "<tr bgcolor=$bgcolor>";
  echo "<td><a name=$row1[0] id=$row1[0]>$row1[0]</td>";
  echo "<td>" . $row1[1] . "</td>";
  echo "<td>" . $row1[5] . "</td>";
  echo "<td>" . $row1[2] . "</td>";
  echo "<td>" . $row1[3] . "</td>";
  echo "<td><input type='checkbox' name='checkbox[]' value=" . $row1[0];
  if ($ok == true) {
    echo 'disabled="disabled" checked="checked"';
  }
  echo "></td>";
  echo "<input type='hidden' name='ServiceID' value=" . $id . ">";
  echo "<input type='hidden' name='Year' value=" . $Year . ">";
  echo "<input type='hidden' name='Stype' value='Recollection'>";

  echo "</tr>";
  } 
}
echo "<tr>
<td colspan='5' align='right' bgcolor='#FFFFFF'><input name='SUBMIT1' type='submit' id='SUBMIT'value='SUBMIT'></td>
</tr>";

How can implement that on the next load if the value of the checkbox is already available in the database it will now be checked. but if it is not yet existing i can check it and save it to the database.

Upvotes: 1

Views: 855

Answers (1)

John Rasch
John Rasch

Reputation: 63505

I'm guessing the problem lies in this line:

if (mysql_num_rows($result2)>0) {
    $ok == true;
}

It should be:

if (mysql_num_rows($result2)>0) {
    $ok = true;
}

In the first snippet you are just testing if $ok is equal to true, while in the second example an actual assignment to the variable is performed.

Remember:

= != ==

Upvotes: 5

Related Questions