【发布时间】:2018-06-10 08:07:46
【问题描述】:
这是我试图从 url 调用它的函数
public function getParentId($childId)
{
$statment = $this->db->prepare("SELECT parent FROM `person` WHERE id = $childId");
$statment->execute();
$result = $statment->fetchAll();
foreach($result as $output){
return $output['parent'];
}
echo 'You call the function from url';
}
我写了这段代码来从 url 访问函数
if(isset($_GET['action'])){
include_once('Family.php');
$object = new Family;
switch($_GET['action']){
case 'getId':
$object->getParentId($childId);
break;
default;
echo 'There is no function with that name';
break;
}
}
然后我从 Url 传递参数
test.local/Family.php?action=getId&childId=4
输出你从 url 调用函数
但他没有返回 $output['parent'] 为什么?
【问题讨论】:
-
尝试在 PHPMyAdmin 中直接对数据库进行查询,以确认返回了哪些行(如果有)
-
它的工作......我从 index.php 调用该函数,他返回了我想要的。但为什么它不能从 url 调用中工作?
-
为什么你用
$childId而不是$_GET['childId']调用函数?