通过表单PHP传递数组值

时间:2012-10-31 04:21:27

标签: php arrays forms variables post

我有一个包含以下代码的表格:

<?php    
echo '<form action="nba-agent-process-bet.php" method="post">';  
echo '<table cellpadding="0" cellspacing="0" border="1" bordercolor="#585858" width=100%>';      
echo '<tr>';  
echo '<th>Date</th>';  
echo '<th>#</th>';  
echo '<th>Team</th>';  
echo '<th>Money</th>';  
echo '<th>Spread</th>';  
echo '<th>Total</th>';  
echo '</tr>';       
for($i=0 ; $i<10;){  
$AwayTeamSpread = " ";  
$HomeTeamSpread = " ";  
foreach ($xml->Game as $Game) {   
$Date[] = $Game->Date; $AwayTeam[] = $Game->AwayTeam; $HomeTeam[] = $Game->HomeTeam; $AwayRotation[] = $Game->AwayRotation;  
$HomeRotation[] = $Game->HomeRotation; $Total[] = $Game->Total; $OverPrice[] = $Game->OverPrice;  
$UnderPrice[] = $Game->UnderPrice; $Line[] = $Game->Line; $AwayTeamPrice[] = $Game->AwayTeamPrice;  
$HomeTeamPrice[] = $Game->HomeTeamPrice; $AwayTeamMoneyLine[] = $Game->AwayTeamMoneyLine; $HomeTeamMoneyLine[] = $Game->HomeTeamMoneyLine;  
}  
foreach ($xml2->events->event as $event) {  
$Spread = $event->periods->period[0]->spread;  
$TotalPoints = $event->periods->period[0]->total;   
$AHomeRotNum = $event->participants->participant[1];   
$AVisitingRotNum = $event->participants->participant[0];  
$AHomeParticipantName = $event->participants->participant[1];  
$AVisitingParticipantName = $event->participants->participant[0];  
$MoneyLine = $event->periods->period[0]->moneyline;   
$AwayLine[] = $Spread->spread_visiting;   
$HomeLine[] = $Spread->spread_home;  
$UnderAdjust[] = $TotalPoints->under_adjust;   
$OverAdjust[] = $TotalPoints->over_adjust;  
$ATotalPoints[] = $TotalPoints->total_points;  
$VisitingRotNum[] = $AVisitingRotNum->rotnum;  
$HomeRotNum[] = $AHomeRotNum->rotnum;  
$VisitingParticipantName[] = $AVisitingParticipantName->participant_name;  
$HomeParticipantName[] = $AHomeParticipantName->participant_name;  
$AwayMoneyLine[] = $MoneyLine->moneyline_visiting;   
$HomeMoneyLine[] = $MoneyLine->moneyline_home;  
$AwaySpreadAdjust[] = $Spread->spread_adjust_visiting;   
$HomeSpreadAdjust[] = $Spread->spread_adjust_home;  
}     
echo '<tr>';  
echo "<td>$Date[$i]</td><td><table><tr><td>$VisitingRotNum[$i]</td></tr><tr><td>$HomeRotNum[$i]</td></tr></table></td><td><table><tr><td>$VisitingParticipantName[$i]</td></tr><tr><td>$HomeParticipantName[$i]</td></tr></table></td><td><table><tr><td><input type='checkbox' name='AwayMoneyLine' value='$AwayMoneyLine[$i];$HomeParticipantName[$i]'/> $AwayMoneyLine[$i]</td></tr><tr><td><input type='checkbox' name='HomeMoneyLine' value='$HomeMoneyLine[$i];$AwayParticipantName[$i]'/>$HomeMoneyLine[$i]</td></tr></table></td><td><table><tr><td><input type='checkbox' name='$AwaySpreadAdjust[$i]' value='$AwayLine[$i]'/> $AwayLine[$i] ($AwaySpreadAdjust[$i])</td></tr><tr><td><input type='checkbox' name='$HomeSpreadAdjust[$i]' value='$HomeLine[$i]'/> $HomeLine[$i] ($HomeSpreadAdjust[$i])</td></tr></table></td><td><table><tr><td><input type='checkbox' name='AwayTotalPoints' value='$TotalPoints[$i]'/> Over $ATotalPoints[$i]</td></tr><tr><td><input type='checkbox' name='HomeTotalPoints' value='$ATotalPoints[$i]'/> Under $ATotalPoints[$i]</td></tr></table></td>";  
echo '</tr>';  
$i++;  
}  
echo '<tr>';  
echo '<td colspan="3"><input type="submit" name="send" value="Submit"></td><td colspan="3"><input type="button" name="Clear" value="Clear" /></td>';  
echo '</tr>';  
echo ' </table>';  
?>  

基本上,for循环遍历我的xml项目。 foreach循环为数组赋值。数组打印在一个表中,循环中的每个$ i表示表中的一行。当选中并提交了一个复选框时,我想通过复选框中的值传递所选$ i的多个数组。我在表单操作中有以下代码:

例如,我尝试传递$ HomeMoneyLine并回显该值,但没有运气。任何帮助将不胜感激!

<?php session_start(); ?>  
<?php  
if($_POST['AwayMoneyLine'] == $_POST['$AwayMoneyLine']){  
     $bet_type="Moneyline";  
     $HomeTeam=$_POST['$HomeMoneyLine[$i]'];  
     echo $HomeTeam;  
}   
else {   
header("Location: http://www.mainurl.com/");   
}   
?>  

1 个答案:

答案 0 :(得分:1)

if($_POST['AwayMoneyLine'] == $_POST['$AwayMoneyLine']){  
                                     ^--            ^--

除非您使用文字$Aw等作为表单中字段的名称,否则这些可能不是您要查找的引号。