简体   繁体   中英

How to find in mysql_fetch_array while and foreach cycle variables?

I need to do a search in each $row2 variable, so i could find if there is columns that are not equal to $row1 column.

This is what I tried,

$result1 = mysql_query('SELECT gpu FROM ng2s3_content');
$result2 = mysql_query("SELECT gpu FROM bigc3_gpu");

while ($row1 = mysql_fetch_array($result1)) {
while ($row2 = mysql_fetch_array($result2)) {
foreach ($row2 as $ar) {
if ($ar == $row1[0]) {      
            }
            else {
                echo $ar;
            }
        }
    }
}

looks like you want distinct values from your database , use mysql query , that will return a resource with distinct values ,

$result = mysql_query('SELECT gpu FROM ng2s3_content UNION SELECT gpu FROM bigc3_gpu');

while ($row = mysql_fetch_array($result)) {
    echo $row['gpu'];
}

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