dongshi4589 2015-12-14 06:13
浏览 36
已采纳

PHP循环数据

I want to make the first row 'update' button link to A page and second row 'update' button link to B page, but when the PHP function loops it keep showing that both row 'update' button link to the same page.

<?php
    $conn = mysql_connect("localhost","root","");
    mysql_select_db("smart_train",$conn);
    $result = mysql_query("SELECT * FROM detail");
>
<table id="example1" class="table table-bordered table-striped">
    <thead>
          <tr>
             <th>Station Place</th>
             <th>Line1</th>
             <th>Line2</th>
             <th>Line3</th>
             <th>Station Code</th>
             <th>Opening Hours</th>
             <th>Parking</th>
             <th>Content Control</th>
          </tr>
    </thead>

<?php
                        $i=0;
                        while($row = mysql_fetch_array($result)) {
                        if($i%2==0)
                        $classname="evenRow";
                        else
                        $classname="oddRow";
                   ?>
                  <tr class="<?php if(isset($classname)) echo $classname;?>">   
                    <td> <?php echo $row["place"]; ?> </td>
                    <td id="station_line1"> <?php echo $row["line1"]; ?> </td>
                    <td id="station_line2"> <?php echo $row["line2"]; ?> </td>
                    <td id="station_line3"> <?php echo $row["line3"]; ?> </td>
                    <td id="station_code"> <?php echo $row["code"]; ?> </td>
                    <td id="station_opening"> <?php echo $row["opening"]; ?> </td>
                    <td id="station_parking"> <?php echo $row["parking"]; ?> </td>
                    <td>
                        <div class="btn-group">
                          <a href="station_detail _update1.php">
                          <button onclick="myFunction()" type="button" class="btn btn-warning">Update</button>
                          </a>
                          <a><button type="button" class="btn btn-default" id="content_control_or">or</button></a>
                          <a><button type="button" class="btn btn-warning">Delete</button></a>
                          <?php if(isset($message)) { echo $message; } ?>
                      </div>
                    </td>
                  </tr>
                   <?php
                    $i++;
                    }
                   ?>
</tbody>

enter image description here

Can someone help me to solve this problem? I'm quite new to programming.

  • 写回答

1条回答 默认 最新

  • dqcqcqwq38860 2015-12-14 06:20
    关注

    You need to pass variable in anchor of that button to redirect on page where page name will be dependent of $i's value.

    if($i%2==0){
    { 
       $classname="evenRow";
       $goesToPage='Page1.php';
     }
    else{
       $classname="oddRow";
       $goesToPage='Page2.php';
    }
    
         <a href="<?php echo $goToPage; ?>">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题