复选框是否在使用php的2个mysql查询中

I have 2 mysql queries, each lists a range of companies. 1 a complete list and 1 a shorter list.

I am displaying them in a bulleted list and if the same company is in both queries, I would like to check the related checkbox next to it.

At the moment, I can display the complete list no problem, and then check the first one that is in both lists, but it won't check any more that are repeated in both lists.

I have tried while statements, foreach statements and also in_array, but think I must be missing something. Hoping someone can show me the error of my ways.

    $companysolicitors = mysql_query("SELECT * FROM companyselected WHERE companyid='$companyid'");
$companysolicitor = mysql_fetch_array( $companysolicitors );


$mainquery = mysql_query("SELECT * FROM company”);
while($listcompanies = mysql_fetch_array($mainquery)) {


echo  "<input name=‘companies[]' type='checkbox' id='".$listcompanies['companyid']."' data-role='none' value='".$listcompanies['companyid']."’";

    foreach ($companysolicitor as $i) { if ($i == $listcompanies['companyid']) { echo ' checked'; } }

echo  "><label for='".$listcompanies['companyid']."'><span></span>".$listcompanies['companyname']."</label>”;

}

from first query just return for eg cmp_id

like

$companysolicitors = mysql_query("SELECT cmp_id FROM companyselected WHERE companyid='$companyid'"); $companysolicitor = mysql_fetch_array( $companysolicitors );

now it should return array(1,3,8,...) //this just an example

Now your second query is correct

        $mainquery = mysql_query("SELECT * FROM company");
            while($listcompanies = mysql_fetch_array($mainquery)) {
                if(in_array($listcompanies['companyid'], $companysolicitor)){
                    $checked = 'checked="checked"';
                }else{
                    $checked = null;
                }
            echo  "<input name=‘companies[]' type='checkbox' id='".$listcompanies['companyid']."' data-role='none' value='".$listcompanies['companyid']."' $checked/><label for='".$listcompanies['companyid']."'><span></span>".$listcompanies['companyname']."</label>";

        }