I have a string that should control if the checkbox array is checked or not when i open the page that contain checkbox I deal with the string as an array of 0 & 1 if 1=checked

note: I retreive my checkbox values from the database

here is the code:

do{
?>
<tr>
<td><? $cost=$temprow3['cost'];?>

<input type="checkbox" name="pro[]" value="<? echo $cost;?>" <?php
$OK = isset($_POST['pro']);

if ($OK && in_array($cost, $_POST['pro'])) { ?>
checked="checked" <? $spec .="1"; ?>
<?php } else {$spec .="0"; } ?>
<?if($m != " "){
$my=strlen($m);
for ($i=0; $i<$my; $i++)
{

if( $m[$i] ==1 ){

?>
checked="checked" <? }}}?>

/>

<? echo ($temprow3['name']); ?> </td>
<td><? echo $cost;?> </td>
</tr>
<?
}while($temprow3 = $adb->fetch_array($result3));


$m is the String

its not seem to work so if someone know a thing I can do please help
it wont work in php only php deal with HTML side by side. the checkbox is an HTML code, but you control it using php or javascript, or at least thats what I know
anyway its a simple function generating checkbox array by retrieving the data from database, the function:

-------
if ($OK && in_array($cost, $_POST['pro'])) { ?>
checked="checked" <? $spec .="1"; ?>
<?php } else {$spec .="0"; } ?>
-------
used to keep the checkbos checked after posting submit button and create a string that give value 1 if checkbox checked and 0 if checkbox is not checked

-----
if($m != " "){
$my=strlen($m);
for ($i=0; $i<$my; $i++)
{

if( $m[$i] ==1 ){

?>
checked="checked" <? }}}?>
-----
retrieve the string $m which is the array that contain 0&1 values that suppose to control checkbox when the page is opened, so if the string is not empty read it using for loop and if value=1 make check box is checked

this code is inserted in checkbox html code
cuz in the simple code the checkbox code will be
<input type=checkbox name=pro[ ] value=1 checked="checked" />

I need to control (checked="checked") thats why my php code is mixed with html