php查询不返回结果
问题描述:
我试图执行一个php查询没有结果。我一直试图让它工作几个小时,并且认为另一组眼睛会有所帮助。这里是我的脚本:php查询不返回结果
if(!empty($cLvl))
{
$result = $conn->query("SELECT lvl" . $cLvl . "
FROM buyers WHERE buyer_id = $buyer");
$comRate = $result->fetch_assoc();
}
print_r($comRate); die;
$buyer
被发现:
$result = $conn->query("select source_id from inventory where sku = {$data[$n]['sku']}");
if($result) {$buyer = $result->fetch_assoc();}
和$cLvl
被发现:
if($data[$n]['cost'] == 0 || $bookType3['book_type_3'] == "DMG")
{
$cLvl = null;
}
elseif($bookType['book_code'] == "IE" || $bookType['book_code'] == "AIE")
{
$cLvl = 3;
}
elseif($cId['condition_id'] == 1 || $cId['condition_id'] == 2 || $cId['condition_id'] == 3 || $cId['condition_id'] == 4 || $follett['class_code'] == "D" || strpos($follett['notes'],"(T)") == true)
{
$cLvl = 2;
}
elseif($cId['condition_id'] == 5)
{
$cLvl = 1;
}
在我的测试$buyer = 263
和$cLvl = 3
。但是,当我尝试查找$comRate
时,它什么都不返回。如果我在信息中硬编码,我会得到一个结果,但是这将会运行大约250条记录,而且我不能对每条记录进行硬编码。
我在哪里出错了?
答
这段代码有很多错误,但是你要求的可能是你的$buyer
是一个assoc数组,你想用{$buyer['source_id']}
代替。
感谢您的信息,我试过了,我仍然没有从我的print_r($ comRate)中得到任何东西。任何其他想法? – Jim 2012-07-17 19:33:45
尝试打印出“SELECT lvl”。 $ cLvl。 “ FROM buyer WHERE buyer_id = $ buyer”'? – 2012-07-17 19:39:52
我得到SELECT lvl 3 FROM买家WHERE buyer_id = 263当我回显“SELECT lvl”时。 $ cLvl。 “来自买家WHERE buyer_id = $ buyer ['source_id']”这是我所需要的结果,但是就目前而言。 – Jim 2012-07-17 19:45:59