2014-09-02 63 views
0

我沒有嘗試將作爲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

回答

0

而不是

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

使用

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