dougua4836 2015-10-28 13:50
浏览 42
已采纳

PDO选择最大查询不返回任何内容,空白页

So I have a function within a class to take the highest value based on another value but I'm getting a blank page.

I checked for bad syntax but there's none that the validator found and if I change it to header("Location: https://facebook.com") it will go to the site so it seems the function is working. However I am not getting my variable back.

My connections and everything else are fine as my other functions in this class return what I want.

class FORUM
{
    private $forum;

    function __construct($DBFORUM_con)
    {
        $this->db = $DBFORUM_con;
    }

    public function addCount($id)
    {
        try
        {   
            $stmt = $this->db->prepare("SELECT MAX(a_id) AS Maxa_id FROM forum_answer WHERE question_id = :id");

            $stmt->execute(array(':id'=>$id));
            $userRow = $stmt->fetch(PDO::FETCH_ASSOC);

            if ($stmt->rowCount() > 0)
            {
                $Max_id = $userRow['Maxa_id'] + 1;

                return $Max_id;
            }
            else {
                $Max_id = 1;

                return $Max_id;
            }
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }
}

Then in my page that processes the form:

//require class

$id = $_POST['id'];

if ($forum->addCount($id))
{
    echo $Max_id;
}
else
{
    echo $Max_id;
}
  • 写回答

1条回答 默认 最新

  • doulei1965 2015-10-28 14:05
    关注

    You're not assigning the return value to anything.

    Try

    $id = $_POST['id'];
    
    $Max_id = $forum->addCount($id)
    
    if ($Max_id)
    {
        echo $Max_id;
    }
    else
    {
        echo $Max_id;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备