为什么如果......切换到DBO后别停止工作?

时间:2021-08-24 02:54:27

I have this code now.

我现在有这个代码。

$select_links = "SELECT * FROM $table";
if (isset($_POST['link'])) {
    if ($_POST['link'] == '0'){
    }}
else {

$links = $conn->prepare($select_links);
$links->execute();
$links->setFetchMode(PDO::FETCH_ASSOC);  
while($row1 = $links->fetch())
{
echo $row1['name'];
};
}

When I load page without _POST, echo $row1['name']; works. But if I send POST link=1 it dont works. Why? I need to make it not work only if POST contains link=0.

当我在没有_POST的情况下加载页面时,echo $ row1 ['name'];作品。但是,如果我发送POST link = 1它不起作用。为什么?我需要使它不起作用只有POST包含link = 0。

P.S. It works before I switced to DBO.

附:它在我转向DBO之前有效。

1 个解决方案

#1


1  

It is not whatever "DBO" but the code you wrote.
Although I managed to get it's meaning only after reformatting it sanely. Here it goes:

它不是“DBO”,而是您编写的代码。虽然我只是在重新格式化之后才设法得到它的含义。它来了:

$select_links = "SELECT * FROM $table";
if (isset($_POST['link'])) {
    if ($_POST['link'] == '0'){
        // do nothing
    }
} else {
    $links = $conn->prepare($select_links);
    $links->execute();
    $links->setFetchMode(PDO::FETCH_ASSOC);  
    while($row1 = $links->fetch())
    {
        echo $row1['name'];
    }
}

So, when you set POST link=1, it is passed isset($_POST['link']) check and then no other code being executed.

因此,当您设置POST link = 1时,它会通过isset($ _ POST ['link'])检查,然后没有其他代码被执行。

Most likely you meant something like this

很可能你的意思是这样的

if (!empty($_POST['link'])) {
    $select_links = "SELECT * FROM $table";
    $links = $conn->prepare($select_links);
    $links->execute();
    $links->setFetchMode(PDO::FETCH_ASSOC);  
    while($row1 = $links->fetch())
    {
        echo $row1['name'];
    }
}

If you need some other logic - no problem, code whatever behaviour you want.
Just read the manual and test everything you try.
...but okay, this one could be hard for a newcomer:

如果您需要其他逻辑 - 没问题,请编写您想要的任何行为。只需阅读手册并测试您尝试的所有内容。 ......但是没关系,这个对于一个新手来说可能很难:

if (!isset($_POST['link']) || $_POST['link']) {

means

IF $_POST['link'] is NOT set OR $_POST['link'] NOT equal to 0

#1


1  

It is not whatever "DBO" but the code you wrote.
Although I managed to get it's meaning only after reformatting it sanely. Here it goes:

它不是“DBO”,而是您编写的代码。虽然我只是在重新格式化之后才设法得到它的含义。它来了:

$select_links = "SELECT * FROM $table";
if (isset($_POST['link'])) {
    if ($_POST['link'] == '0'){
        // do nothing
    }
} else {
    $links = $conn->prepare($select_links);
    $links->execute();
    $links->setFetchMode(PDO::FETCH_ASSOC);  
    while($row1 = $links->fetch())
    {
        echo $row1['name'];
    }
}

So, when you set POST link=1, it is passed isset($_POST['link']) check and then no other code being executed.

因此,当您设置POST link = 1时,它会通过isset($ _ POST ['link'])检查,然后没有其他代码被执行。

Most likely you meant something like this

很可能你的意思是这样的

if (!empty($_POST['link'])) {
    $select_links = "SELECT * FROM $table";
    $links = $conn->prepare($select_links);
    $links->execute();
    $links->setFetchMode(PDO::FETCH_ASSOC);  
    while($row1 = $links->fetch())
    {
        echo $row1['name'];
    }
}

If you need some other logic - no problem, code whatever behaviour you want.
Just read the manual and test everything you try.
...but okay, this one could be hard for a newcomer:

如果您需要其他逻辑 - 没问题,请编写您想要的任何行为。只需阅读手册并测试您尝试的所有内容。 ......但是没关系,这个对于一个新手来说可能很难:

if (!isset($_POST['link']) || $_POST['link']) {

means

IF $_POST['link'] is NOT set OR $_POST['link'] NOT equal to 0