简体   繁体   English

从php文件中创建带有两个按钮的表单以选择操作

[英]Make a form with two buttons from a php file to choose an action

i have the following html: 我有以下html:

<body onload="showcontent()"> <!-- onload optional -->
        <div id="content"><img src="loading.gif"></div> <!-- leave img out if not onload -->
    </body>

I also have the following script: 我也有以下脚本:

function showcontent(){ 函数showcontent(){

  if(window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
  } else {
    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  }

  xmlhttp.onreadystatechange = function() {
    if(xmlhttp.readyState == 1) {
        document.getElementById('content').innerHTML = "<img src='loading.gif' />";
    }
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      document.getElementById('content').innerHTML = xmlhttp.responseText;
    } 
  }

  xmlhttp.open('GET', 'elsevier.php', true);
  xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  xmlhttp.send(null);

}

In elsevier.php I want when the rows of a table exceed 500 two buttons to be displayed, telling me whether to continue or cancel. 在elsevier.php中,我希望当表的行数超过500时显示两个按钮,告诉我是继续还是取消。 If I put this code in the .php file nothing happens..... (except that two buttons appear). 如果我将此代码放在.php文件中,则什么也不会发生.....(除了出现两个按钮)。

if(mysqli_errno($con)==1062){
                    @$q55="SELECT COUNT(*) FROM testarticles";
                    $result55 = mysqli_query($con, $q55);
                    $row = $result55->fetch_row();
                    echo '#: ', $row[0].'<br>';

                    if($row[0]>=500&&$answer==false){
                        echo '<form action="" method="GET">';
                        echo "<label>Do you want to continue or cancel?</label>";
                        echo '<input type="button" id="but1" name="but1" value="Continue">';
                        echo '<input type="button" id="but2" name="but2" value="Cancel">';
                        echo '</form>';

                        //sleep(2);

                        if(isset($_GET["but1"])){
                           $answer=true;
                           break;
                         }
                         elseif(isset($_GET["but2"])){
                           @$q56="DELETE * FROM journal, volume, issue, articles, testarticles WHERE import_time=$unixtimestamp";
                           $result56 = mysqli_query($con, $q56);
                           exit;
                         }
                    }

I want in this step the execution of the php script to stop and to display me the two buttons to choose from. 我想在这一步中停止php脚本的执行,并向我显示两个按钮供您选择。 If i press continue i want the script to execute from where it was stopped. 如果我按继续,我希望脚本从停止处执行。

Has anybody any idea?? 有人知道吗? Thank you in advance! 先感谢您!

session_start();

if(mysqli_errno($con)==1062){ 

                $where = isset($_SESSION['last_id']) ? " WHERE id > '" . $_SESSION['last_id'] . "'" : "";
                if(isset($_SESSION['last_id']))
                    unset($_SESSION['last_id']);

                @$q55="SELECT COUNT(*) FROM testarticles$where ORDER BY id"; 
                $result55 = mysqli_query($con, $q55); 
                $row = $result55->fetch_row(); 
                echo '#: ', $row[0].'<br>'; 

                if($row[0] >= 500 && $answer == false){

                    $_SESSION['last_id'] = $row['id'];

                    echo "<label>Do you want to continue or cancel?</label>"; 
                    echo '<input type="button" id="but1" name="but1" value="Continue" onclick="showcontent(true)" />'; 
                    echo '<input type="button" id="but2" name="but2" value="Cancel">'; 

                    //sleep(2); 

                    if(isset($_GET["but1"])){ 
                       $answer=true; 
                       break; 
                     } 
                     elseif(isset($_GET["but2"])){ 
                       @$q56="DELETE * FROM journal, volume, issue, articles, testarticles WHERE import_time=$unixtimestamp"; 
                       $result56 = mysqli_query($con, $q56); 
                       exit; 
                     } 
                } 

You have to modify also the showcontent function because when you press the continue button the content retrieved should be appended and not replaced 您还必须修改showcontent函数,因为当您按下继续按钮时,检索到的内容应该附加而不是替换。

function showcontent(){
  if(window.XMLHttpRequest) {           
    xmlhttp = new XMLHttpRequest();           
  } else {           
    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');           
  }           

  xmlhttp.onreadystatechange = function() {           
    if(xmlhttp.readyState == 1 && !update) {           
        document.getElementById('content').innerHTML = "<img src='loading.gif' />";           
    }           
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      if(update)
        alert("this is an update and I should append data, not to replace the div content");
      else {       
        document.getElementById('content').innerHTML = xmlhttp.responseText;           
        //this is the first call of the function so the content of the div will be replaced
      }
    }            
  }           

  xmlhttp.open('GET', 'elsevier.php', true);           
  xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');           
  xmlhttp.send(null);           

}

HTML Code: HTML代码:

<body onload="showcontent(false)"> <!-- onload optional -->              
   <div id="content"><img src="loading.gif"></div> <!-- leave img out if not onload -->              
</body> 

Note that this is not a verified code so you should modify it 请注意,这不是经过验证的代码,因此您应该对其进行修改

use ' echo ' followed by the < html code > for creating a button. 使用' echo '后跟< html code >来创建按钮。 You will be done. 您将完成。

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

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