$user_id = $id['id'];
$shop_name = $_POST['shop_name'];
$query = mysqli_query($con, "SELECT * FROM sh_subscriptions s INNER JOIN shopaholic f ON s.feed_id = f.feed_id WHERE s.user_id = '". $user_id ."' AND f.shop_name = '" . $shop_name . "'") or die(mysqli_error($con));
while($row = mysqli_fetch_array($query))
{
var_dump($row['feed_id'])
}
尽管变量按预期填充,但仍返回null。
我认为问题在于使用'
和"
,因为我的文字编辑器没有显示我期望的颜色。
答案 0 :(得分:0)
问题在于双引号和单引号。此外,由于$user_id
INTEGER
不是必需的,;
之后var_dump($row['feed_id'])
是$user_id = $id['id'];
$shop_name = $_POST['shop_name'];
$query = mysqli_query($con, "SELECT * FROM sh_subscriptions s INNER JOIN shopaholic f ON s.feed_id = f.feed_id WHERE s.user_id = $user_id AND f.shop_name = '$shop_name'") or die(mysqli_error($con));
while($row = mysqli_fetch_array($query))
{
var_dump($row['feed_id']);
}
。再试一次:
{{1}}
答案 1 :(得分:0)
顺便说一下,在我看来,这个数字更具可读性......
$query = "
SELECT *
FROM sh_subscriptions s
JOIN shopaholic f
ON s.feed_id = f.feed_id
WHERE s.user_id = $user_id
AND f.shop_name = '$shop_name';
";
$result = mysqli_query($con, $query) or die(mysqli_error($con));
答案 2 :(得分:0)
$user_id = $id['id'];
$shop_name = $_POST['shop_name'];
$query = mysqli_query($con, "SELECT * FROM sh_subscriptions s INNER JOIN shopaholic f ON s.feed_id = f.feed_id WHERE s.user_id = '". $user_id ."' AND f.shop_name = '" . $shop_name . "'") or die(mysqli_error($con));
while($row = mysqli_fetch_array($query))
{
var_dump($row['feed_id'])
}
以下是对未来应该做/考虑的事情:
$sql
中,然后在mysqli_query($sql)
中运行。它更容易调试并使代码更具可读性。*
运算符选择所有列。准确定义您要拉的列。更好的性能,使代码更易于管理。协助调试:
在firefox上安装firebug并在FF上运行测试。你也可以使用chrome,但我更喜欢FF。
$sql
。然后使用firebug来获得响应。显然,这会导致javascript错误,因为这不会返回JSON或其他常规数据时间。我知道这里有很多文字,但是如果我编码的话,这就是你的代码的样子。意识到背景中有很多东西,但至少你了解如何设置100%证明系统:
$user_id = $_SESSION['user_id'];
$shop_name = $form->validate('POST', 'shop_name', some_validation);
if ($form->is_valid()) {
$sql = "SELECT s.column1, s.column2
FROM sh_subscriptions s
INNER JOIN shopaholic f ON s.feed_id = f.feed_id
WHERE s.user_id = $user_id AND f.shop_name = '{$extender->sanitizeSQL($shop_name['valid']}'";
// Run query and insert the results into '$result_name' variable
$mysqli->query($sql, 'result_name');
// If at least one row
if ($result_name->num_rows > 0) {
// Process code
}
else {
// No records
}
}
else {
// Invalid user input
}