多个查询并分开然后进行绑定?

时间:2016-06-12 18:58:11

标签: php mysql mysqli mysqli-multi-query

是否可以在同一个.php中进行多个查询并绑定它们以在不同的地方显示?

例如我使用:



<?php
include 'dbc.php';
$query = "SELECT art_price, art_header, art_pic, art_row1, art_row2, art_row3, art_row4 FROM signs WHERE art_number = ?";

if($stmt = $conn->prepare($query)){
    $stmt->bind_param('s', $_POST['art_number']);
    $stmt->execute();
    $stmt->bind_result($rowPrice, $rowHeader, $rowPic, $rowArt1, $rowArt2, $rowArt3, $rowArt4);


    while($stmt->fetch()){
        
        ?>
&#13;
&#13;
&#13;

然后用

显示结果
<?=$rowPic?>

但我想能够使用另一个&#34; $ _ POST [&#39; art_number2&#39;]&#34;受到约束

<?=$rowPic2?>

这可能吗?如何? 感谢答案!

将此更改为:

&#13;
&#13;
<?php
include 'dbc.php';
$query = "SELECT art_price, art_header, art_pic, art_row1, art_row2, art_row3, art_row4 FROM signs WHERE art_number = ?";

if($stmt = $conn->prepare($query)){
    $stmt->bind_param('s', $_POST['art_number']);
    $stmt->execute();
    $stmt->bind_result($rowPrice, $rowHeader, $rowPic, $rowArt1, $rowArt2, $rowArt3, $rowArt4);
    $stmt->bind_param('s', $_POST['art_number2']);
    $stmt->execute();
    $stmt->bind_result($rowPrice2, $rowHeader2, $rowPic2, $rowArt12, $rowArt22, $rowArt32, $rowArt42);


    while($stmt->fetch()){
        
        ?>
&#13;
&#13;
&#13;

现在只有第二个选择显示为结果。

1 个答案:

答案 0 :(得分:0)

<?php
include 'dbc.php';
$query = "SELECT art_price, art_header, art_pic, art_row1, art_row2, art_row3, art_row4 FROM signs WHERE art_number = ?";

if($stmt = $conn->prepare($query)){
    $stmt->bind_param('s', $_POST['art_number']);
    $stmt->execute();
    $stmt->bind_result($rowPrice, $rowHeader, $rowPic, $rowArt1, $rowArt2, $rowArt3, $rowArt4);

    while($stmt->fetch()){

        ?> ... <?php
    }

    $stmt->bind_param('s', $_POST['art_number2']);
    $stmt->execute();
    $stmt->bind_result($rowPrice2, $rowHeader2, $rowPic2, $rowArt12, $rowArt22, $rowArt32, $rowArt42);


    while($stmt->fetch()){

        ?>