【问题标题】:PHP to report status of MSSQL query table select intoPHP报告MSSQL查询表的状态选择进入
【发布时间】:2017-05-18 02:41:10
【问题描述】:

我有一个按钮:

<a href="#" onclick="loadPage('admin_manualsend.php?refresh=true'); return false;">
    <i class="fa fa-refresh"></i> 1. Refresh Now
</a>

点击它会加载同一个页面,它是一个刷新=true的页面,所以现在当页面加载时会触发:

if(isset($_GET["refresh"]) && $_GET["refresh"]=="true"){
    $res = db_query("begin try drop table [TmpTable] end try begin catch end catch");
    $res = db_query("SELECT * INTO [TmpTable] FROM [dbo].[ViewLive]");
}

这需要一段时间,我希望它报告 table drop 是否成功,并报告它现在正在传输的记录的计数,然后当它完成时,如下所示:

if(isset($_GET["refresh"]) && $_GET["refresh"]=="true"){
    $res = db_query("begin try drop table [TmpTable] end try begin catch end catch");
    Show modal, echo 'Drop done'; (or drop failed)
    WHILE ( $res = db_query("SELECT * INTO [TmpTable] FROM [dbo].[ViewLive]");
    echo 'Count of current record' 
    count of record +1
    )
    echo 'Update done'; 
    (user can then close modal)
}

我该怎么做?我使用:PHP、MSSQL、脚本 src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">

谢谢

更新:

    function db_query($query) {
    global $conn;
    $res = sqlsrv_query($conn, $query);
    return $res;
}

function db_fetch_array($res) {
    $result = array();
    while( $array = sqlsrv_fetch_array($res) ) {
          $result[count($result)] = $array;    
    }  
    sqlsrv_free_stmt($res);
    return $result;
}

function db_fetch_row($res) {                   
    $array = sqlsrv_fetch_array($res);
    sqlsrv_free_stmt($res);
    return $array;
}

function db_fetch_one($res) {                   
    $array = sqlsrv_fetch_array($res);
    sqlsrv_free_stmt($res);
    return $array[0];

【问题讨论】:

  • loadPage() 的代码在哪里?
  • @CodeGodie 我不确定你的意思是什么对不起。可能是这个,我在帖子的更新下添加了:)
  • 我的意思是你的a标签中的函数,这里:onclick="loadPage('admin_manualsend.php?refresh=true');正在寻找一个名为loadPage()的JS函数,我想知道那个代码在做什么,你能发布那个函数也一样?

标签: php jquery sql


【解决方案1】:

我不确定你到底想要做什么,但如果你使用 ajax,你可以在不离开页面的情况下执行你的 sql,并获得一个很好的成功或错误回调!

// put this in your document ready function for index.html
$("#submit").on("click", function() {
  $.ajax({
    type: "post",
    url: "process.php",
    data: "action=SomeActionHere",
    success: function(data) {
      alert("SUCCESS");
    },
    error: function(e) {
      alert("ERROR");
    }
  });
};
<!--index.html -->
<button id="submit">GOGO</button>

<!--process.php-->

<?php 
header("Content-type: application/json; charset=utf-8");
//connect to the server

$action = $_POST['action'];

if($action == "SomeActionHere"){

// do you sql stuff here

// when done sql
echo json_encode("SUCCESS"); // whatever data you want to send back

}

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多