使用从PHP中的mysql表返回的值


Using values returned from a mysql table in PHP

我正试图从表中检索数据(出于安全原因,我将更改特定表和列的所有名称),并使用它来"忽略"代码中的某些元素。

例如,我有一个名为table_one的表,其值为:A.BCD我想用这些值来"忽略"字母表中的字母(a、b、c、d),并将其余的打印到屏幕上。我尝试过使用fetch_array和in_array来有效地过滤返回给我的结果,但这些对我不起作用

它的工作方式大致如下:

$to_ignore = array(
    "A", 
    "B", 
    "C", 
    "D");
$qry = mysql_query("SELECT * FROM table_one");
while ($results = mysql_fetch_array($qry))
{
    foreach ($to_ignore as $ignore_this)
    {
        if (!in_array($ignore_this, $results))
        {
            //do when you need to
        }
    }
}

但出于某种原因,当我这样做时,只有第一个结果被忽略(A),其余的都没有,有人能帮上忙吗?

in_array不适用于多维数组。因此,您需要定义这些值可能出现的列名。像

while ($results = mysql_fetch_array($qry))
{
    foreach ($to_ignore as $ignore_this)
    {
        if (!in_array($ignore_this, $results['mycolumn'])) // specify the column 
        {
            //do when you need to
        }
    }
}