如何为PHP循环中创建的按钮创建函数?

时间:2015-07-22 04:53:17

标签: php

while($record = mysql_fetch_array($myData)){
if(($record['Opponent'] == "") && ($record['better_name'] != $_SESSION['user_name'])){

    $acceptID = "accept" . $record['bet_ID'];
    echo "<form action=index.php method=post>";
    echo "<input type=submit name=" . $acceptID . " value="ACCEPT">"; 
    echo "<input type=hidden id=" . $record['bet_ID'] . ">"; 
    echo "</form>";
} elseif (($record['Opponent'] == "") && ($record['better_name'] == $_SESSION['user_name'])){
    echo "<form action=index.php method=post>";
    echo "<input type=submit name=delete value=DELETE>";
    echo "<input type=hidden id=" . $record['bet_ID'] . ">"; 
    echo "</form>";
} else {
    echo "Game Locked.";

1 个答案:

答案 0 :(得分:0)

我试图通过$_POST['ACCEPT']$_POST['DELETE']命令传递bet_ID&#39; s。事实证明,我并不需要每个输入/按钮的表格。这对我有用:

## $record['bet_ID'] was pulled from an SQL database table.


echo "<input type=hidden name=accept value='$record[bet_ID]'>";
echo "<input type=submit value=Accept>";

$date = $_POST['accept'];
echo $date;