将参数发送到嵌套在 PHP 页面中的动态 PHP


Send argument to dynamic PHP nested inside a PHP page

我有两页测试1.php和测试2.php。

我只想在 test1 上点击提交.php和 test2.php显示在div 中。这实际上工作正常,但我需要向 test2 传递一个参数.php以限制从 mySQL 数据库显示的结果(包含 3000 个项目的数据库只有一个结果)。

老实说,我认为这是在javascript中,但只是不确定如何去做。

test1.php 是

<html>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
// Handler for .ready() called.
$('#SubmitForm').submit(function( event ) {
    $.ajax({
            url: 'test2.php',
            type: 'POST',
            dataType: 'html',
            data: $('#SubmitForm').serialize(),
            success: function(content)
            {
                $("#DisplayDiv").html(content);
            }  
    });
    event.preventDefault();
});
});
</script>
<body>
    <div id="page">
        <form id="SubmitForm" method="post">
            <div id="SubmitDiv" style="background-color:black;">
                <button type="submit" class="btnSubmit">Submit</button>
            </div>
        </form>
        <div id="DisplayDiv" style="background-color:red;">
            <!-- This is where test2.php should be inserted -->
        </div>
    </div>
</body>

测试2.php是

$pageNum_test1 = 0;
if (isset($_GET['pageNum_test1'])) {
  $pageNum_test1 = $_GET['pageNum_test1'];
}
$startRow_test1 = $pageNum_test1 * $maxRows_test1;
mysql_select_db($database_wing, $wing);
$query_test1 = "SELECT * FROM pilots";
$query_limit_test1 = sprintf("%s LIMIT %d, %d", $query_test1, $startRow_test1, $maxRows_test1);
$test1 = mysql_query($query_limit_test1, $wing) or die(mysql_error());
$row_test1 = mysql_fetch_assoc($test1);
if (isset($_GET['totalRows_test1'])) {
  $totalRows_test1 = $_GET['totalRows_test1'];
} else {
  $all_test1 = mysql_query($query_test1);
  $totalRows_test1 = mysql_num_rows($all_test1);
}
$totalPages_test1 = ceil($totalRows_test1/$maxRows_test1)-1;
?>
<div id="page" style="background-color:yellow;">
    <?php do { ?>
      <?php
        echo "Hello World.";
        echo $row_test1['firstname']
    ?>
      <?php } while ($row_test1 = mysql_fetch_assoc($test1)); ?>
</div>
<?php
mysql_free_result($test1);
?>
url: 'test2.php?pageNum_test1=' + num,

我想这就是你想要的。