简体   繁体   中英

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

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?

in_array does not work with multidimensional 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
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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