将结果查询存储到视图表中?这是可能的?

问题描述 投票:-2回答:2

我有一个盒子来获取两个时期之间的项目。当放置两个范围时,我的搜索完成,并根据我的查询的其余部分,这将显示在我的html中的表格中。

我想在表或视图上保存相同的查询,而不是生成Echo。也许是这样的:

$sql = "SELECT * from eequipamentos2 " . $queryCondition . " ORDER BY datas_final2 desc ";
$result = mysqli_query($conn,$sql);
$faq = $db_handle->runQuery($sql);

$mysqli = new mysqli("localhost", "root", "", "newbd");
if (!$mysqli->query("DROP table IF EXISTS test") ||
!$mysqli->query("CREATE TABLE test (`descricao2` VARCHAR(60), `componente2` VARCHAR(60))")
!$mysqli->query("INSERT INTO test (col1, col2, col3, ...) SELECT col1, col2, col3, ... FROM ...$result??????"))
echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
php sql mysqli tableview store
2个回答
0
投票

感谢您的建议:当您注意到我刚刚更新了帖子,并根据建议我发布了我想要运行的代码。以下是我的总代码:

<? php
$ output = '';
$ conn = mysqli_connect ("localhost", "root", "", "newbd");
require_once ("example / dbcontroller.php");
$ db_handle = new DBController ();


$ post_at = "";
$ post_at_to_date = "";

$ queryCondition = "";
if (! empty ($ _ POST ["search"] ["post_at"])) {
$ post_at = $ _POST ["search"] ["post_at"];
list ($ fid, $ end, $ fiy) = explode ("-", $ post_at);

$ post_at_todate = date ('Y-m-d');
if (! empty ($ _ POST ["search"] ["post_at_to_date"])) {
$ post_at_to_date = $ _POST ["search"] ["post_at_to_date"];
list ($ tid, $ tim, $ tiy) = explode ("-", $ _ POST ["search"] ["post_at_to_date"]);
$ post_at_todate = "$ tiy- $ tim- $ tid";
}

$ queryCondition. = "WHERE final_data2 BETWEEN '$ fiy- $ fin- $ fid' AND '". $ post_at_todate. "'";
}

    
$ sql = "SELECT * from andequipment2". $ queryCondition. "ORDER BY datas_final2 desc";
$ result = mysqli_query ($ conn, $ sql);
$ faq = $ db_handle-> runQuery ($ sql);

$ mysqli = new mysqli ("localhost", "root", "", "newbd");
if (! $ mysqli-> query ("DROP table IF EXISTS test") ||
    ! $ mysqli-> query ("CREATE TABLE test (` description2` VARCHAR (60), `component2` VARCHAR (60)))
    ! $ mysqli-> query ("INSERT INTO new_table (col1, col2, col3, ...) SELECT col1, col2, col3, ... FROM ... $result??????"))
    echo "Table creation failed: (". $ mysqli-> errno. ")". $ mysqli-> error;
?>

0
投票

最后,我想分享完成的代码,以便从$ result查询中保存数据库中的结果。

这解决了我的问题。

[<?php
$output='';
    $conn = mysqli_connect("localhost", "root", "", "newbd");
    require_once("exemplo/dbcontroller.php");
$db_handle = new DBController();


    $post_at = "";
    $post_at_to_date = "";

    $queryCondition = "";
    if(!empty($_POST\["search"\]\["post_at"\])) {           
        $post_at = $_POST\["search"\]\["post_at"\];
        list($fid,$fim,$fiy) = explode("-",$post_at);

        $post_at_todate = date('Y-m-d');
        if(!empty($_POST\["search"\]\["post_at_to_date"\])) {
            $post_at_to_date = $_POST\["search"\]\["post_at_to_date"\];
            list($tid,$tim,$tiy) = explode("-",$_POST\["search"\]\["post_at_to_date"\]);
            $post_at_todate = "$tiy-$tim-$tid";
        }

        $queryCondition .= "WHERE datas_final2 BETWEEN '$fiy-$fim-$fid' AND '" . $post_at_todate . "'";
    }


    $sql = "SELECT * from eequipamentos2 " . $queryCondition . " ORDER BY datas_final2 desc ";
    $result = mysqli_query($conn,$sql);
    $faq = $db_handle->runQuery($sql);


    $mysqli = new mysqli("localhost", "root", "", "newbd");
if (!$mysqli->query("DROP table IF EXISTS test") ||
    !$mysqli->query("CREATE TABLE test (`setor2` VARCHAR(60), `descricao2` VARCHAR(60), `componente2` VARCHAR(60), `qtdadesugerida2` VARCHAR(60), `lubrificante2` VARCHAR(60), `qtdadeaplicada2` VARCHAR(60), `status2` VARCHAR(60))"))

    echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error;




     if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $row1 = $row\["setor2"\];
        $row2 = $row\["descricao2"\];
        $row3 = $row\["componente2"\];
        $row4 = $row\["qtdadesugerida2"\];
        $row5 = $row\["lubrificante2"\];
        $row6 = $row\["qtdadeaplicada2"\];
        $row7 = $row\["status2"\];







 //Insert Data to another table
            $sql1 = "INSERT INTO test (setor2, descricao2, componente2, qtdadesugerida2, lubrificante2, qtdadeaplicada2, status2)
            VALUES ('$row1','$row2','$row3','$row4','$row5','$row6','$row7');";
            if (mysqli_multi_query($conn, $sql1)) {
                echo "New records created successfully";
            } else {
                echo "Error: " . $sql . "<br>" . mysqli_error($con);
            }
        //echo "id: " . $row\["d1"\]. " - Name: " . $row\["d2"\]. " " . $row\["d3"\]. "<br>";
    }
} else {
    echo "0 results";
}    




?>][1]
© www.soinside.com 2019 - 2024. All rights reserved.