PHP SQL结果存储为新SQL查询中的变量

PHP SQL结果存储为新SQL查询中的变量,php,mysql,Php,Mysql,所以这是一个php游戏等等 这是我剧本的主要部分 $sql = "SELECT * from search1 WHERE username='Hitachi'"; $result = mysqli_query($connection, $sql); while ($rows = mysqli_fetch_array($result)) { $timeleft = $rows['time']; $target55 = $rows['target']; $id = $row

所以这是一个php游戏等等

这是我剧本的主要部分

$sql = "SELECT * from search1 WHERE username='Hitachi'";
$result = mysqli_query($connection, $sql);

while ($rows = mysqli_fetch_array($result)) {
    $timeleft = $rows['time'];
    $target55 = $rows['target'];
    $id = $rows['id'];
    $status = $rows['status'];
    $hours = $rows['hours'];
    $started = $rows['started'];
    $deletetime = $started - 86400;

    mysqli_query($connection, "DELETE FROM search WHERE started<'$deletetime'");
    $starttime = $started;
    $time1 = $starttime + 10800;

    $a_query = mysqli_query($connection, "SELECT * FROM BG WHERE username='$target55' AND status='Ready'");
    $check_found = mysqli_num_rows($a_query);

    if ($check_found >= 1) {
        $bg = mysqli_query($connection, "SELECT * FROM BG WHERE status='Ready' AND username='$target55' ORDER by slot DESC LIMIT 1");
        while ($i = mysqli_fetch_object($bg)) {
            $bg1 = $i->bodyguard;
        }

        echo "This user has a bodyguard called <b>$bg1</b>!";
        if ($time1 < time() && $hours >= 3 || $userlevel >= 14) {
            $sql2 = "SELECT * from users WHERE username='$target55'";
            $result2 = mysqli_query($connection, $sql2);
            while ($rows2 = mysqli_fetch_array($result2)) {
                $target_country = $rows2['country'];
            }

            mysqli_query($connection, "UPDATE search1 SET status='2', location='$target_country', found='$target_country' WHERE id='$id'");
        }

        mysqli_query($connection, "DELETE FROM BG WHERE username='$target55'");
$sql=“从search1中选择*,其中username='Hitachi'”;
$result=mysqli\u查询($connection,$sql);
while($rows=mysqli\u fetch\u数组($result)){
$timeleft=$rows['time'];
$target55=$rows['target'];
$id=$rows['id'];
$status=$rows['status'];
$hours=$rows['hours'];
$started=$rows['started'];
$deletetime=$started-86400;

mysqli_query($connection,“从搜索中删除已启动的位置启用PHP错误报告,添加
添加错误报告时,我没有收到任何错误,如果我删除保镖检查,这一切都会起作用,但当我添加保镖检查时,它应该通过(无保镖)它什么也不做,当有保镖的时候,它不会说有?我自由地格式化了你的代码。这不是更容易阅读吗?;-)就像我说的,你也应该通过
echo mysqli_error($connection)从MySQL中返回错误(如果有)
。您确定
$bg
查询返回了任何行吗?这也可能是一个逻辑错误(好像您的
如果
没有检查正确的东西,或者没有考虑所有的可能性)。$target55目前不会返回任何行,因此它应该执行“更新搜索1集…”。。。"sql查询。当有行时,它应该显示$b1查询?而且它更容易阅读,谢谢如果你看缩进,你会看到你更新的查询在里面,如果没有行,它将永远不会到达那么远,并执行可更新的PHP错误报告,添加
我在添加er时没有收到任何错误ror_报告,如果我删除保镖检查,这一切都会起作用,但是当我添加保镖检查时,当它应该通过(没有保镖)时,它什么也不做,当有保镖时,它不会说有?我随意格式化了你的代码。难道不是更容易阅读吗?;-)就像我说的,你也应该从MySQL中得到错误(如果有的话)使用
echo mysqli_error($connection);
。您确定
$bg
查询返回了任何行吗?它也可能是一个逻辑错误(好像您的
如果
没有检查正确的事情,或者没有考虑所有的可能性)。$target55目前不会返回任何行,因此它应该继续“update search1 set…”sql查询。当有行时,它应该显示$b1查询?另外,它更易于阅读,谢谢。如果您查看缩进,您会看到您更新的查询位于if内,因此如果没有行,它将永远不会到达那么远并执行更新