mysql运行3个查询得到空白页

e4eetjau  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(366)

我使用php和mysql运行follow查询,但是如果我只查询1个查询,它就工作了,但是如果我执行3个查询,它就不工作了
知道为什么吗?
似乎是while$))导致了问题,但尝试了很多方法,结果什么也没有显示

$boletas = mysqli_query($datacenter, "
    SELECT * FROM ventas 
    WHERE documento = 'boleta' 
    ORDER BY id DESC LIMIT 1");
$facturas = mysqli_query($datacenter, "
    SELECT * FROM ventas WHERE documento = 'factura' 
    ORDER BY id DESC LIMIT 1");
$notas = mysqli_query($datacenter, "
    SELECT * FROM ventas 
    WHERE documento = 'nota' 
    ORDER BY id DESC LIMIT 1");
while($mostrar = mysqli_fetch_assoc($revisar)){
    while($boleta = mysqli_fetch_assoc($boletas)) {
        while($factura = mysqli_fetch_assoc($facturas)) {?>

                <select class="selects" > 
                    <option value="3" data-price="
                    <?php
                    echo str_pad($boleta['folio'] + 1, 15, "0", STR_PAD_LEFT);
                    ?>">
                boleta</option>
                <option value="4" data-price="
                <?php
                echo str_pad($factura['folio'] + 1, 15, "0", STR_PAD_LEFT);
                ?>">factura</option>
                <option value="5" data-price="
                <?php
                echo str_pad($nota['folio'] + 1, 15, "0", STR_PAD_LEFT);
                ?>">nota de venta</option>
            </select>

            <input type="text" class="inputs" 
            value="<?php
            echo str_pad($boleta['folio'] + 1, 15, "0", STR_PAD_LEFT);
            ?>">

            <?php
        }
    }
    }
    ?>

它只是显示了一个空白页,使用所有3个查询,但如果我使用1个查询,我得到了正确的结果疯狂

bwleehnv

bwleehnv1#

问题是 mysql_fetch_assoc 使用上一次的结果 mysqli_query 打电话。如果你想修复你的代码,你必须循环第一次的结果 mysqli_query 使用 mysql_fetch_assoc ,将其存储在一个数组中,循环遍历该数组,然后执行内部 mysqli_query ,然后重复。

<?php
$boletas_query = mysqli_query($datacenter, "
    SELECT * FROM ventas 
    WHERE documento = 'boleta' 
    ORDER BY id DESC LIMIT 1");

$boletas = array();

while ($boleta = mysqli_fetch_assoc($boletas)) {
    $boletas[] $boleta;
}

$facturas_query = mysqli_query($datacenter, "
    SELECT * FROM ventas WHERE documento = 'factura' 
    ORDER BY id DESC LIMIT 1");

$facturas = array();

while ($factura = mysqli_fetch_assoc($facturas)) {
    $facturas[] = $factura;
}

$notas_query = mysqli_query($datacenter, "
    SELECT * FROM ventas 
    WHERE documento = 'nota' 
    ORDER BY id DESC LIMIT 1");

$notas = array();

while ($nota = mysqli_fetch_assoc($notas)) {
    $notas[] = $nota;
}

foreach ($boletas as $boleta) {
    ?>
    <?php
    foreach ($facturas as $factura) {
        ?>
        <?php
        foreach ($notas as $nota) {
            ?>

            <select class="selects" > 
                <option value="3" data-price="
                <?php
                echo str_pad($boleta['folio'] + 1, 15, "0", STR_PAD_LEFT);
                ?>">
            boleta</option>
            <option value="4" data-price="
            <?php
            echo str_pad($factura['folio'] + 1, 15, "0", STR_PAD_LEFT);
            ?>">factura</option>
            <option value="5" data-price="
            <?php
            echo str_pad($nota['folio'] + 1, 15, "0", STR_PAD_LEFT);
            ?>">nota de venta</option>
        </select>

        <input type="text" class="inputs" 
        value="<?php
        echo str_pad($boleta['folio'] + 1, 15, "0", STR_PAD_LEFT);
        ?>">

        <?php
    }
}
}
?>

但是,我不建议这样做,因为您可以通过一个查询实现所需的功能,而且它在数据库上的效率要高得多。
另外,在这里提问时,请缩进并格式化代码。我必须通过一个文本编辑器来格式化它,以便能够阅读它。

相关问题