首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将带有mysqli_fetch_row的选择传递给表

问将带有mysqli_fetch_row的选择传递给表
EN

Stack Overflow用户
提问于 2022-04-29 00:28:40
回答 1查看 74关注 0票数 -2

在传递返回多条记录的查询时,我遇到了问题,我已经使用了返回输入的select,但这只适用于一条记录,但需要显示多条记录,所以查询带来的所有内容都需要放在一个表中。

代码语言:javascript
复制
<?php 
$conexion=mysqli_connect('localhost','root','mysql','venta3');
$continente=$_POST['continente'];

    $sql1="SELECT cobro, debe,idEntrega FROM inventario Where (idCliente='$continente'AND (cantidadP>0 or cantidadM>0 OR cantidadG>0))";

    $result2=mysqli_query($conexion,$sql1);
    $cadena2="<select id='cobroDebe' name='cobroDebe' style='width:400px;'  class='chosen-choices2'>";

    while ($ver2=mysqli_fetch_row($result2)) {
        $cadena2=$cadena2."<option value='".utf8_encode($ver2[1])."'>".utf8_encode($ver2[1])."</option>";       
    }
    echo  $cadena2."</select>";
    
    $result1=mysqli_query($conexion,$sql1);
    $cadena1="<select id='cobroEntre' name='cobroEntre' style='width:400px;'  class='chosen-choices2'>";

    while ($ver1=mysqli_fetch_row($result1)) {
        $cadena1=$cadena1."<option value='".utf8_encode($ver1[0])."'>".utf8_encode($ver1[0])."</option>";       
    }
    echo  $cadena1."</select>";
    
    
    $result3=mysqli_query($conexion,$sql1);
    $cadena3=" ";

    while ($ver3=mysqli_fetch_row($result3)) {
        $cadena3=$cadena3."<input type='hidden' id='idEntrega' name='idEntrega'
            value='".utf8_encode($ver3[2])."'>";
            }

    echo  $cadena3;
     ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-09 13:54:23

我不打算为您编写整个解决方案,但我将向您展示如何使第一个选择安全地从DB中填充,并从中看到和学习其他内容。

代码语言:javascript
复制
$conexion=mysqli_connect('localhost','root','mysql','venta3');
$continente=$_POST['continente'];
    // Build the query with ? to prepare later
    $sql1="SELECT cobro, debe,idEntrega FROM inventario Where (idCliente=? AND (cantidadP>0 or cantidadM>0 OR cantidadG>0))";
    // Prepare the statement
    $stmt = $conexion->prepare($sql1);
    // Bind the params
    $stmt->bind_param("s", $continente);
    // Attempt to execute
    if ($stmt->execute()) {
        // if successful, get result
        $result = $stmt->get_result();
        // If query brought any rows
        if ($result->num_rows > 0) {
            // build the select
            $cadena2="<select id='cobroDebe' name='cobroDebe' style='width:400px;'  class='chosen-choices2'>";
            // Fetch assoc array from the result
            while ($ver2 = $result->fetch_assoc()) {
                // use it
                $cadena2=$cadena2."<option value='". $ver2[1] ."'>". $ver2[1] ."</option>";
            }
            echo  $cadena2."</select>";
        }
    // if execution failed - echo the error
    } else {
        echo $stmt->error;
    }
    // free result and close statement
    $result->free_result();
    $stmt->close();
    // You can reuse $stmt and $result because we've now freed them

请注意while循环$ver21可能不会给您带来任何信息。你必须看看你的数据库返回了什么。我会用$ver2,$ver2‘debe,$ver2'idEntrega’

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72051583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档