tags:

views:

157

answers:

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

+5  A: 

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:

= != ==
John Rasch
I love that rule, what's it called in english? in Dutch it's Ezelsbruggetje, it is, rule of thumb?
Pim Jager
According to Wikipedia, Ezelsbruggetje literally translates to mnemonic, which is any simple memory aid such as "Every Good Boy Does Fine" (EGBDF, for the notes on a music staff from bottom to top). Rule of thumb describes my example perfectly because they are not always unequal (VB for example).
John Rasch