通过URL php传递动态变量

时间:2013-09-04 00:47:23

标签: php mysql url variables

我不确定标题,我尽我所能。 我有一个表格,其中显示了使用此文件的数据库中的信息

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的新页面。我需要点击的行中的人员用户名和锦标赛名称。

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

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

'join.php名称= thierusernamehere&安培; tourname = dfgdds'

任何帮助非常感谢。感谢。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

有很多方法可以接近。

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

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

BUT

您的代码确实很乱,尝试使代码更易于维护和读取。并且不要使用任何mysql_*函数,不推荐使用它们。

了解有关PDO的更多信息:

相关问题