2013-05-04 29 views
-1

我從DB一些值,並從用戶獲取數組值和投入,同時

$foo = array(); 
$query2 = mysql_query("SELECT item_audit_id FROM mod_users_files"); 
while ($row = mysql_fetch_assoc($query2)) { 
$foo['item_audit_id'] = $row; 

穿上陣列結果

GET當我打印print_r($foo);我得到正確的價值觀,像

Array ([item_audit_id] => Array ([item_audit_id] => 13)) 

Array ([item_audit_id] => Array ([item_audit_id] => 1)) 

現在,我又過了一段時間,並且很想檢查item_audit_id是否存在並向用戶顯示信息:

<tbody> 
    <?php 
    $i = 0; 
    while ($i < $num) { 
     $class_item_id = mysql_result($result,$i,"class_item_id"); 
     $class_item_descrption = mysql_result($result,$i,"class_item_description"); 
     ?> 
     <tr class="grade"> 
      <td><?php echo $class_item_id; ?></td> 
      <td><?php echo $class_item_description; ?></td> 
      <td> 
       <?php 
       if (in_array($class_item_id, $foo)) { 
        echo "<p style='color:green'>Exist</p>"; 
       } else { 
        echo "<p style='color:red'>Missing</p>"; 
       } 
       ?> 
      </td> 
     </tr> 
     <?php 
     $i++; 
    } 
    ?>      
</tbody> 

如果我聲明數組中這樣說:

$foo = array("1", "2", "3", "4", "5", "6"); 

結果是正確的,在下面時我不能得到任何結果。

我在哪裏錯了?

謝謝大家的幫助;

+0

您已經忘記了我$ class_item_descrption – 2013-05-04 21:58:25

+0

哪裏'$ result'來自重新分配這個變量? '$ num'定義在哪裏? – Oswald 2013-05-04 21:58:45

+0

我認爲用PDO代替mysql_ *會更好。今天學習,明天仍然有效。今天不學習昨天的工作。 – hakre 2013-05-04 22:01:02

回答

0

你一遍又一遍

$foo['item_audit_id'] = $row; 

你可能想

$foo[] = $row['item_audit_id']; 
+0

謝謝史蒂夫。解決了 :-) – user2307958 2013-05-04 22:05:13