繁体   English   中英

通过URL php传递动态变量

[英]Pass a dynamic variable through URL php

我不确定标题,我已经尽力了。 我有一个显示该表的数据库,其中包含使用此文件的数据库信息

Display.php的

<?php

    mysql_connect("localhost", "root", "root") or die(mysql_error());
    mysql_select_db("tournaments") or die(mysql_error());

    $result = mysql_query("SELECT * FROM tournies") 
    or die(mysql_error());  

    echo '<table id="bets" class="tablesorter" cellspacing="0" summary="Datapass">
<thead>
    <tr>
        <th>Tournament <br> Name</th> 
        <th>Pot</th> 
        <th>Maximum <br> Players</th> 
        <th>Minimum <br> Players</th> 
        <th>Host</th> 
        <th></th>
        <th></th>
    </tr>
</thead>
<tbody>';



    while($row = mysql_fetch_array( $result )) {

       $i=0; if( $i % 2 == 0 ) {
            $class = "";
        } else {
            $class = "";
        }

        echo "<tr" . $class . "><td>"; 
        echo $row['tour_name'];
        $tour_id = $row['tour_name'];
        echo "</td><td>"; 
        echo $row['pot']," Tokens";
        echo "</td><td class=\"BR\">"; 
        echo $row['max_players']," Players";
        echo "</td><td class=\"BR\">"; 
        echo $row['min_players']," Players";
        echo "</td><td class=\"BR\">";
        echo $row['host'];
        echo "</td><td>";
        echo "<input id=\"delete_button\" type=\"button\" value=\"Delete Row\" onClick=\"SomeDeleteRowFunction(this)\">";
        echo "</td><td>";
        echo "<form action=\"join.php?name=$name\" method=\"POST\" >";
        echo "<input id=\"join_button\" type=\"submit\" value=\"Join\">";
        echo "</td></tr>"; 
    } 

    echo "</tbody></table>";
?>

基本上,我希望用户从表的一行中按下按钮,然后转到一个名为join.php的新页面。 我需要从单击的行中获得人员的用户名和比赛的名称。

例如,这是我的页面: 我的页面

当他们单击第一行末尾的加入按钮时,应将其发送到

'join.php?NAME = thierusernamehere&tourname = dfgdds'

任何帮助,不胜感激。 谢谢。

echo '<td><a href="join.php?name='.$row['name'].'&tourname='.$row['tour_name'].'">Join</a></td>'

有很多方法可以解决。

最简单的方法是echo '<a href="join.php?name=' . $row['col_name'] . '">JOIN</a>';

或者您可以使用带有隐藏的输入和提交按钮的表单。

您的代码确实是一团糟,请尝试使您的代码更具可维护性和可读性。 并且不要使用任何mysql_*函数,它们已被弃用。

进一步了解PDO:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM