SQL将表更新两次,但只应更新一次

时间:2017-05-21 22:13:23

标签: php sql mysqli prepared-statement

这让我大吃一惊......

如果我删除更新语句,它根本不会更新“视图”......这样就可以了。

如果我删除“删除html”并运行该文件,它将更新一次而不是它应该两次?这根本没有意义

这怎么可能,特别是当只有一个更新查询和需要删除的纯HTML时?

如果有人有兴趣,如果你不相信我,我准备做团队观察。

这是示例page

为了便于阅读,将所有代码分隔成块

$stmt = $dbCon->prepare("SELECT id, views, rating, votes FROM rating ORDER BY id DESC LIMIT 1");
$stmt->execute();
$stmt->bind_result($id, $views, $rating, $votes);
$stmt->fetch();
$stmt->close();
$average = averageRate($rating, $votes);

$string1;
$string1 .= "<p>Id = " . $id . "</p><br>";
$string1 .= "<p>Views = " . $views . "</p><br>";
$string1 .= "<p>Rating = " . $rating . "</p><br>";
$string1 .= "<p>Votes = " . $votes . "</p><br>";
$string1 .= "<p>Average = " . averageRate($rating, $votes) . "</p><br><br>";

更新查询

//THIS IS THE UPDATE QUERY PROBLEM
//UPDATERE DATABASED
$stmt = $dbCon->prepare("UPDATE rating SET
    views = views + 1 WHERE id = ?");
$stmt->bind_param('i', $id);
$stmt->execute();
$stmt->close();

删除HTML(如果我删除这个HTML的SQL更新一次,很奇怪吧?JS是什么用于HTML)

<div class="topNav">
    <span class="topNavArrow">
    </span>
    <div class="categoryWrapper">
        <div id="categoryParent">
            <input id="category01" class="categorys" type="checkbox" value="1" checked>
            <input id="category02" class="categorys" type="checkbox" value="2" checked>
            <input id="category03" class="categorys" type="checkbox" value="3" checked>
        </div>
        <label for="category01">
            <img src="#" alt="category 01">
        </label>
        <label for="category02">
            <img src="#" alt="category 02">
        </label>
        <label for="category03">
            <img src="#" alt="category 03">
        </label>
    </div>
</div>


<script>
    document.querySelector("#categoryParent").addEventListener("click", checkedCategory, false);
    var categorys = document.getElementsByClassName("categorys");
    var categorysLength = categorys.length;
    var checked = "1,2,3";
    function checkedCategory(e) {
        checked = "";
        for (var c = 0; c < categorysLength; c++) {
            if (checked) {
                var separator = ",";
            } else {
                var separator = "";
            }
            if (categorys[c].checked) {
                checked += separator + categorys[c].value;
            }
        }
        alert(checked);
        e.stopPropagation();
    }
</script>

HTML的其余部分

<div id="contentWrapper" class="contentWrapper">
    <?php echo $string1;?>
    <div class="contentInner">
        <div class="contentHelper">
            <div class="contentInfo">
                <p id="contentViews">Views: <?php echo $views; ?></p>
                <p>Votes: <?php echo $votes; ?> </p>
                <p>Average: <?php echo $average; ?>/5</p>
                <p class="<?php echo $voteYesNo; ?>"><?php echo $voteText ?></p>
            </div>
            <div class="contentImg">

            </div>
        </div>
    </div>
</div>

搜索了STO,但我发现任何问题都没有解决我的问题,但有些像这样的类似link

这不是一个糟糕的笑话,它真的发生了什么......

0 个答案:

没有答案