简体   繁体   English

PHP将报告MSSQL查询表的状态选择为

[英]PHP to report status of MSSQL query table select into

I have a button: 我有一个按钮:

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

and on click it loads the same page it is one with refresh=true so now when the page loads it triggers this: 并在单击时加载同一页面,它是带有refresh = 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]");
}

It takes a while and I'd like it to report that the table drop was successful or not and also report the count of which record it is now transferring, and then when it finishes so something like this: 需要一些时间,我希望它报告表删除是否成功,并且还报告它现在正在传输的记录的计数,然后报告完成的时间,如下所示:

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)
}

How would I do this? 我该怎么做? I use: PHP, MSSQL, script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"> 我使用:PHP,MSSQL,脚本src =“ // ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”>

Thank you 谢谢

Update: 更新:

    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];

I am not sure exactly what you are trying to do, but if you use ajax you can do your sql without leaving the page AND get a nice callback for success or error! 我不确定您要做什么,但是如果您使用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 } ?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM