dpbe81245 2014-04-08 14:28
浏览 36
已采纳

PHP if和while语句不能正常工作

I have php code with two queries. One is in an Oracle database, with the result being about 100 rows of data (within the data there are SKU numbers). The other is in a mysql database with about 30 rows of data (with the data there are also SKU numbers).

I need to compare each SKU in the first query to the second query, line by line. If the SKU in the first query also appears in the second query, then I need it to echo the SKU.

All SKUs in the second query are in the first query, so I would expect the result to echo all 30 SKUs, but it does not. Depending on how I change the syntax, it echos 17 rows, 100 rows, or no rows at all.

It's worth noting that both queries work fine. The Oracle query is insanely long and has a lot of sub-queries in it, so I will not include that full query below. The Oracle query returns the results perfectly in SQL Developer, and the MySQL query returns the results perfectly in HeidiSQL. Both queries have been tested and echoed as tables in other php files to make sure that they were working fine.

Below is what the php file that I am trying to fix looks like so far;

<?php

$conn = oci_connect($user, $pswd, $hst);
$sql = oci_parse($conn,"[Really long Oracle Query]");

while ($row = oci_fetch_assoc($sql))
{
    $sku = $row['SKU'];
    $con = mysql_connect("[database host]", "[database user]", "[database password]");
    mysql_select_db("[database_name]");
    $sqls = "SELECT * FROM [table_name] WHERE [this_date_column] BETWEEN 
        DATE_SUB(NOW(), INTERVAL 14 DAY) AND NOW()";
    $result = mysql_query($sqls);
    $mailer = NULL;

    while($rows = mysql_fetch_assoc($result))
    {
        $m_sku = $rows['sku'];
        if ($m_sku == $sku)
        {
            $mailer == 'false';
        }   
    }
    if ($mailer == 'false')
    {
        echo $m_sku;
        echo "<br>";
    }       
}

?>

Again; there are only 30 SKUs in the MySQL query, but over 100 SKUs in the Oracle query. All SKUs in the MySQL query are definitely in the Oracle query.

Anyone see what I am doing wrong?

Thanks in advance,

-Anthony

  • 写回答

2条回答 默认 最新

  • douban2014 2014-04-08 14:41
    关注

    You have basic sintacsis errors:
    = is used to assign values
    == compares 2 variables (not counsidering there type *)
    === compares 2 variables including there types.

    your code should look something like this:

    while($rows = mysql_fetch_assoc($result))
        {
            $m_sku = $rows['sku'];
            if ($m_sku == $sku)
            {
                $mailer = false; // == is for comparison, = is for assign
            }   
        }
        if ($mailer === false)
        {
            echo $m_sku;
            echo "<br>";
        }   
    

    if($member == 'false'){...}

    when 'false' is compared with == to a falsefull value (0, null, false, array(), '') .. it will NOT be mach it as it is parsed as a "not empty string" so it is not falsefull .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛