简体   繁体   English

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

[英]Using values returned from a mysql table in PHP

I am trying to retrieve data from a table (for security reasons I am going to change all names of specific tables and columns), and use it to "ignore" certain elements of the code. 我试图从表中检索数据(出于安全原因,我将更改特定表和列的所有名称),并使用它“忽略”代码的某些元素。

For instance I have a table named table_one, with the values: ABCD And I want to use the values to "ignore" the letters of the alphabet (a, b, c, d) and print the rest to the screen. 例如,我有一个名为table_one的表,其值:ABCD并且我想使用这些值“忽略”字母表中的字母(a,b,c,d),并将其余部分打印到屏幕上。 I have tried to use the fetch_array and in_array to effectively filter the results the were returned to me, these do not work for me. 我尝试使用fetch_array和in_array有效地过滤返回给我的结果,这些对我不起作用。

A rough idea of the way it is working is as follows: 大致的工作方式如下:

$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
        }
    }
}

But for some reason, when I do this, only the first result is ignored (A) and the rest are not, could anyone help with this? 但是由于某种原因,当我这样做时,只有第一个结果被忽略(A),而其余的则没有,有人可以帮忙吗?

in_array does not work with multidimensional array. in_array不适用于多维数组。 So you would need to define the column name where these values might come. 因此,您将需要定义这些值可能出现的列名称。 Like 喜欢

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
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM