duanjianshen4871 2015-09-27 17:52 采纳率: 100%
浏览 48
已采纳

如何使链接记住它在传输之前作为href的值,以便在下一页中使用

With research, I was able to come up with a neat way to display information in my database into a php page.

Now my next aim is to link each row to another php page that will recognize what account ID the user has clicked

echo "<table border='1'>
<tr>
<th>Account ID</th>
<th>Account Username</th>
<th>Account Password</th>

<th>Account First Name</th>
<th>Account Middle Name</th>
<th>Account Last Name</th>

<th>Account Phase</th>
<th>Account Block - Lot</th>
<th>Account Subdivision</th>

<th>Account Contact Number</th>
<th>Account Email Address</th>
<th>Account Status</th>

</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['acc_no'] . "</td>";
echo "<td>" . $row['acc_user'] . "</td>";
echo "<td>" . $row['acc_pass'] . "</td>";

echo "<td>" . $row['acc_fname'] . "</td>";
echo "<td>" . $row['acc_mname'] . "</td>";
echo "<td>" . $row['acc_lname'] . "</td>";

echo "<td>" . $row['acc_phase'] . "</td>";
echo "<td>" . $row['acc_blk-lot'] . "</td>";
echo "<td>" . $row['acc_subd'] . "</td>";

echo "<td>" . $row['acc_contact_num'] . "</td>";
echo "<td>" . $row['acc_email_address'] . "</td>";
echo "<td>" . $row['acc_status'] . "</td>";

echo "</tr>";
}
echo "</table>";

I tried this echo "<td><a href='target php page here'>" . $row['acc_no'] . "</td>" but all the links generated will have the same value. I think JQuery might be needed for this or something but unfortunately, this stuff is not yet taught in our school or there might be a better work around for my problem. please help.

  • 写回答

1条回答 默认 最新

  • duanpu1963 2015-09-27 19:17
    关注

    I am not sure how to integrate the logic inside a While loop, I mean as long as the loop is not finished, does this mean the $_GET or $_POST will loop with it?

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    // Step 1.
    // Create a custom URL that points to this same script, 
    // passing the account number as a $_GET parameter.
    echo '<td><a href="thisScript.php?id=' . $row['acc_no'] . '">' . $row['acc_no'] . "</a></td>";
    echo "<td>" . $row['acc_user'] . "</td>";
    echo "<td>" . $row['acc_pass'] . "</td>";
    
    echo "<td>" . $row['acc_fname'] . "</td>";
    echo "<td>" . $row['acc_mname'] . "</td>";
    echo "<td>" . $row['acc_lname'] . "</td>";
    
    echo "<td>" . $row['acc_phase'] . "</td>";
    echo "<td>" . $row['acc_blk-lot'] . "</td>";
    echo "<td>" . $row['acc_subd'] . "</td>";
    
    echo "<td>" . $row['acc_contact_num'] . "</td>";
    echo "<td>" . $row['acc_email_address'] . "</td>";
    echo "<td>" . $row['acc_status'] . "</td>";
    
    echo "</tr>";
    
    // Step 2.
    // Check if the user has already clicked a one of the URLs we custom made in step 1.
    if (isset($_GET['id'] && $_GET['id'] == $row['acc_no']){
         // the user has, so let's allow them to change the fields.
         // This form appears directly under the record that was clicked.
         echo '<form action="commitChangesScript.php" method="post">';
         echo '<input type="text" name="fname">';
         //repeat for any fields you want to be able the change.
         // ...
         echo '</form>';
    }
    }
    

    First create the custom URLs, this can be done without a form by simply creating a link to the location with a query string at the end of it.

    On the first page load, isset($_GET['id'] will never be true, because the user presumably hasn't selected an account yet. The first page load create the table as well as all the links for specific users. The URLs are unique because they are created using the account number. For account #1, the URL is pointed at thisScript.php?id=1, for account #987 the URL is thisSciprt.php?id=987.

    When the user selects an account number, a new form appears allowing them to change fields. This works because $_GET['id'] will be set to the account number that was selected. We can compare that input with the field in the DB allowing all other rows not to have the form.

    This is just an example of what would work. The form included would interrupt the <table> which might look kind of gross.

    does this mean the $_GET or $_POST will loop with it?

    $_GET and $_POST are defined outside of the while, meaning they will not be repeatedly defined. They are however, within scope inside the while loop as demonstrated in the example I've shown.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!