douju6850 2017-12-05 20:34
浏览 36

不知道从哪里开始在php中选择一行

Ok guys I know this might not be the correct way to ask a question but I have looked as far as I could go. I am a bit stuck on how to go about this problem, probably why I can't find a solution to it. I have a form that the info gets inserted to a db, then you are able to view the info from the database on another page that list everything inserted. My question is how would I go about selecting a row from the table that displays all the info from a row on the db and redirect to another page to edit it? I want to redirect to another page to view/edit all the info.

What I think would work is in the table that shows the info I could put a radio box and have a button at the top to click to edit that row. I don't really know how to assign that radio button to the actual row however.

Here is my table:

<?php
                $sql = "SELECT * FROM employees ORDER BY LastName";
                $result = $mysqli -> query($sql);

                if ($result->num_rows > 0) {
                    echo "
                    <table class='table table-hover table-responsive'>
                        <thead class='thead-dark'>
                            <tr>
                                <th class='table-primary' scope='col'>#</th>
                                <th class='table-primary' scope='col'>First Name</th>
                                <th class='table-primary' scope='col-1'>M.I.</th>
                                <th class='table-primary' scope='col'>Last Name</th>
                                <th class='table-primary' scope='col'>Phone</th>
                                <th class='table-primary' scope='col'>Address</th>
                                <th class='table-primary' scope='col'>Email</th>
                                <th class='table-primary' scope='col'>Birth Date</th>
                                <th class='table-primary' scope='col'>EID</th>
                                <th class='table-primary' scope='col'>Gender</th>
                                <th class='table-primary' scope='col'>Ethnicity</th>
                                <th class='table-primary' scope='col'>Status</th>
                                <th class='table-primary' scope='col'>Hours</th>
                                <th class='table-primary' scope='col'>EAP Access</th>
                            </tr>
                          </thead>";
                    // output data of each row
                    while ($row = $result->fetch_assoc()) {
                        echo "
                        <tbody>
                            <tr class='table-dark'>
                                <td>" . $row['UserID']. "</td>
                              <td>" . $row['FirstName']. "</td>
                              <td>" . $row['Middle']. "</td>
                              <td>" . $row['LastName']. "</td>
                                <td>" . $row['PrimaryPhone']. "</td>
                                <td>" . $row['Address'] . $row['City'] . $row['State'] . $row['Zipcode']. "</td>
                                <td>" . $row['Email']. "</td>
                                <td>" . $row['DateOfBirth']. "</td>
                                <td>" . $row['EID']. "</td>
                                <td>" . $row['Gender']. "</td>
                                <td>" . $row['Ethnicity']." </td>
                                <td>" . $row['Status']. "</td>
                                <td>" . $row['Hours']. "</td>
                                <td>" . $row['eapAccess']. "</td>
                            </tr>
                        </tbody>";
                    }
                    echo "</table>";
                } else {
                    echo "0 results";
                }
            ?>

If I added a <input type="radio" name="selected"> before the userID column like and had a button to select that row, how would I be able to have that row display on a seperate page?

I am still new to php, but this is beyond me and can't find anything remotely close to an answer.

  • 写回答

2条回答 默认 最新

  • douyanjing0822 2017-12-05 21:24
    关注

    Few steps to be done:

    1. add the input radio before before the user ID
    2. wrap whole table with the <form> elements with defined method and action attributes
    3. add the submit button inside the form to send the values
    4. on next script you will receive the value within $_GET or $_POST
    5. process all what you need with received user ID

    Study more about (search internet for more info):

    • HTML forms
    • PHP Form Handling
    • PHP GET and POST Method Tutorials
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算