比较GET数组值和记录集循环值

问题描述:

我没有尝试将作为GET传递的数组中的值与数据库记录集do/while循环中的值进行比较。如果GET数组中的任何值与记录集标识相匹配,我试图使复选框检查。如果您在网址中只使用一个不带逗号的兴趣ID,它就可以工作。谢谢。比较GET数组值和记录集循环值

我的网址是: interestSearch.php利益= 3(这工作) interestSearch.php利益= 3.8(不工作)

<? require('db.php'); 

mysql_select_db($database_data); 
$query_allInterests = "SELECT * FROM interests"; 
$allInterests = mysql_query($query_allInterests, $data) or die(mysql_error()); 
$row_allInterests = mysql_fetch_assoc($allInterests); 
$totalRows_allInterests = mysql_num_rows($allInterests); 

?> 


<form method="get"> 

<? do { ?> 
<input <? 

if(isset($_GET['interests']) && $_GET['interests'] != "") { 


$theCounter = 0; 
$theArray = array($_GET['interests']); 



     foreach ($theArray as $value) {    
//   if ($value == $row_allInterests['id']) {$theCounter++;} 
      if (in_array($row_allInterests['id'], $theArray)) {$theCounter++;}  
     } 





if($theCounter > 0){echo "checked";} 


} 


?> name="<? echo $row_allInterests['id']; ?>" class="doCheck" type="checkbox" id="<? echo $row_allInterests['id']; ?>" value="<? echo $row_allInterests['id']; ?>" /> <? echo $row_allInterests['interest']; ?><br /> 
<? } while ($row_allInterests = mysql_fetch_assoc($allInterests)); ?> 

</form> 
+0

(我删除从标题的解决,作为解决问题1的社会各界人士的指示在被接受的答案上) – 2014-09-02 16:10:07

而不是

$theArray = array($_GET['interests']); 

使用

$theArray = explode(',', $_GET['interests']);