dongping1689 2019-03-27 17:53
浏览 64

PHP循环适用于localhost但在服务器上

I have a weird problem. I read all related topic but there was no any solution for me. There are bunch of php codes on my project and all work perfectly but that one :

<?php
    require("connection.php");
    $query = "SELECT * FROM mrf WHERE completed=0 AND archive IS NULL ORDER BY projectname";
    $get = $db->prepare($query);
    $get->execute();
    if ($get->rowCount()!=0){
    foreach ($get as $res) {
      '<li class="list-group-item"><span class="font-weight-bold">Product(s) : </span>';
      $pieces = explode(",", $res['products']);
      $pieces_count = count($pieces);
      for ($i=0; $i <= $pieces_count -1 ; $i++) { 
        $query2 = "SELECT * FROM suppliers WHERE id = :id";
        $get2 = $db->prepare($query2);
        $get2->bindValue(":id",$pieces[$i]);
        $get2->execute();
        if ($get2->rowCount()!=0){
          foreach ($get2 as $res2) {
            echo $res2['name'].'<b>/</b>';
          }
       }
    }       
    echo '</li>';

It works localhost perfectly but on server the result is empty.

  • I have checked the error(s)

     error_reporting(E_ALL);
     ini_set('display_errors', 1);
    

But there is no any error. Also If there had been an error, I would have seen it on localhost, because error_reporting works on localhost as well as on live server.

  • I checked typos, no any typo
  • Checked cpanel everything related to PHP. All is OK. By the way php ver is 5.6

  • Any idea??

-----------------------------------RESULT----------------------------

-I have checked all codes again and didn't find any error. -I contacted my hosting company. They said my server has reached RLimitMEM (don't know what it is) So they increased my RlimitMEM value. - I amnot satisfied with hosting company's answer but the code is working now. - I appreciate for all answers and advices.

  • 写回答

2条回答 默认 最新

  • douxuqiao6394 2019-03-27 18:15
    关注

    Replace your code with the following and check

    <?php
    require("connection.php");
    $query = "SELECT * FROM mrf WHERE completed=0 AND archive IS NULL ORDER BY projectname";
    $get = $db->prepare($query);
    $get->execute();
    if ($get->rowCount()!=0){
    foreach ($get as $res) { ?>
      '<li class="list-group-item"><span class="font-weight-bold">Product(s) : 
    </span>';
      <?php 
      $pieces = explode(",", $res['products']);
      $pieces_count = count($pieces);
      for ($i=0; $i <= $pieces_count -1 ; $i++) { 
        $query2 = "SELECT * FROM suppliers WHERE id = :id";
        $get2 = $db->prepare($query2);
        $get2->bindValue(":id",$pieces[$i]);
        $get2->execute();
        if ($get2->rowCount()!=0){
          foreach ($get2 as $res2) {
            echo $res2['name'].'<b>/</b>';
          }
        }
      }
      echo '</li>';
     }
    }
    

    You have not closed the PHP, closing curly braces were not there...

    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像