weixin_54219174
2022-05-29 11:33
采纳率: 60%
浏览 34
已结题

PHP 怎么修改这段代码 让下拉菜单点击提交后可以跳转到相应页面

img


<?php
    $link = mysqli_connect('localhost','root','root','db_chengji','3306');
    mysqli_set_charset($link,'utf8');
    $sql1 = "select * from `tb_info` ORDER BY `id` ASC ";
    $mysqli_result1 = mysqli_query($link,$sql1);
    $recount = mysqli_num_rows($mysqli_result1);
    $pagesize = 7;
    $pageno = $_GET['pageno'] ? $_GET['pageno'] : 1;
    $pagecount = ceil($recount / $pagesize);
    $offset = ($pageno-1) * $pagesize;
    $sql = "select * from `tb_info` ORDER BY `id` ASC limit $offset,$pagesize";
    $mysqli_result1 = mysqli_query($link,$sql);
    echo "<table align='center' border='1' style='border-collapse: collapse' width='450'>";
    echo "<tr>";
    while($field = mysqli_fetch_field($mysqli_result1))
        echo "<th>".$field->name."</th>";
    echo "</tr>";
    $j = 0;
    while($row = mysqli_fetch_object($mysqli_result1)) {
        $j++;
        echo "<tr>";
        echo "<td>" . $row->id . "</td>";
        echo "<td>" . $row->name . "</td>";
        echo "<td>" . $row->sex . "</td>";
        echo "<td>" . $row->class . "</td>";
        echo "<td>" . $row->hobby . "</td>";
        echo "</tr>";
    }

    for($i = $j;$i<$pagesize;$i++){
        echo "<tr>";
        echo "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
        echo "</tr>";

    }
    $arr=array();
    echo "<tr><th colspan='5'>";
    for($pageno = 1;$pageno <= $pagecount;$pageno ++){
        echo "<a href='?pageno=$pageno'>$pageno</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        $arr[]=$pageno;
    }
    //print_r($arr);
    echo "<select name='sel'>";
    foreach($arr as $key=>$value){
        echo "<option value=\"key\">第{$value}页</option>";
    }
    echo"<form name='form1' method='post' action=''>
            <input type='submit' name='bt' value='提交' >
            <a href='?pageno=$pageno'>
        </form>";
    if(isset($_POST['bt']))
        
echo "</select>";
    echo "</th></tr>";
    echo "</table>";

1条回答 默认 最新

相关推荐 更多相似问题