dpxf81245 2011-11-25 05:55
浏览 52
已采纳

与`if``seven`和`while`混淆

I have a code where it should check if the result equals to 8 it need to show something and if not it need to show something else and all of that happens inside of a while loop.

while ($row_fpages2 = mysql_fetch_array($result_fanpage2))
{
    if ( $row_fpages2['client'] != NULL ) {

        //GRAPHS
    $sql = "SELECT likes, date FROM statistics_pages WHERE idnum = '".$idnum."' AND page_name = '".$row_fpages2['page_name']."' ORDER BY `statistics_pages`.`date` DESC LIMIT 8";
    $result2 = mysql_query($sql) or die(mysql_error());

    if ($result2) {
        $data   = array();

        while ($row = mysql_fetch_assoc($result2)) {
            $data[]   = $row["likes"];
        }

    if ($result2 == 8) {
    $c_data = count($data)-1;
    $final = array();
    for ($i = 0; $i < $c_data; $i++) {
    $final[] = getZeroResult($data[$i], $data[$i+1]);
}
    $data_string = join(",", $final);

    $stats = '<img src="http://chart.apis.google.com/chart?chs=240x140&cht=ls&chd=t:0,0|'.$data_string.'&chg=20,20&chls=0.75,-1,-1|6,4,1&chm=o,FF9900,1,-1,7,-1|b,3399CC44,0,1,0"></img>';

    } else {
        $stats = '<img src="images/stats_un.jpg"></img>';
    };



    } else {
        print('MySQL query failed with error: ' . mysql_error());
    }

echo '...';

The problem is that the first output always showing the ( == 8) (even if it is not equals to 8) instead of the else output.

Then if i have 2 or more everything comes above the first one is correct but the first one is still showing the ( == 8).

Any help?

  • 写回答

2条回答 默认 最新

  • doujiyong7604 2011-11-25 05:58
    关注

    You do the following which is incorrect:

    $result2 = mysql_query($sql) or die(mysql_error());
    ...
    if ($result2 == 8) {
    

    The return value of mysql_query is a resource not an int. What is that you are trying to do there ?

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么