Help with nested loops please
Posted: Wed Apr 28, 2010 11:41 am
Hello All,
I am having troubles getting my code to work properly. Basically what I have is a page where people can bet on games, if they bet on the game I would like the game (which is a table) to disappear. Since there will be multiple users betting I need to make sure that it checks whether the person currently logged in has made a bet on the game or not.
so here is my thought process:
if (game has not been bet on){
display game
}
else {
if ( game has been bet on and the member_id that bet is != to the current user){
continue;
}
else {
display game
}
}
------------------------------------
Here is my code for that section, any suggestions would be appreciated. The website is bigtenbetting.com if anyone wants to look.
Thanks for any help, this is due Friday for a project and I'm kind confused why it isn't working

I am having troubles getting my code to work properly. Basically what I have is a page where people can bet on games, if they bet on the game I would like the game (which is a table) to disappear. Since there will be multiple users betting I need to make sure that it checks whether the person currently logged in has made a bet on the game or not.
so here is my thought process:
if (game has not been bet on){
display game
}
else {
if ( game has been bet on and the member_id that bet is != to the current user){
continue;
}
else {
display game
}
}
------------------------------------
Here is my code for that section, any suggestions would be appreciated. The website is bigtenbetting.com if anyone wants to look.
Code: Select all
while($gameinfo = mysql_fetch_array( $data )){
//if there is no bet on game; display game
if(is_null($gameinfo['sport_event'])){
echo "<form id=\"betForm\" name=\"betForm\" method=post action=\"bet-exec.php\">";
$sport_event_id = $gameinfo['sport_event_id'];
$homeID = $gameinfo['home_id'];
$awayID = $gameinfo['away_id'];
$data2 = mysql_query("SELECT school_name, team_id FROM teams WHERE team_id='$homeID'")
or die(mysql_error());
$data3 = mysql_query("SELECT school_name, team_id FROM teams WHERE team_id='$awayID'")
or die(mysql_error());
$homeschool = mysql_fetch_array( $data2 );
$awayschool = mysql_fetch_array( $data3 );
$home = $homeschool['school_name'];
$away = $awayschool['school_name'];
echo "<table align=\"center\">
<thead>
<tr>
<th width=\"167\" scope=\"col\">".$gameinfo['game_date']."</th>
<th width=\"94\" scope=\"col\">".ucwords($gameinfo['sport'])."</th>
<th width=\"79\" scope=\"col\">Team ID</th>
<th width=\"216\" scope=\"col\">Teams</th>
<th width=\"70\" scope=\"col\">Selection</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope=\"row\"><input type=submit name=submit_bet value=\"Place Bet\" /></th>
<td colspan=\"4\"><input name=\"bet_amt\" type=text class=textfield id=\"bet_amt\" /></td>
<td><input name=sport_event_id type=hidden value=$sport_event_id /></td>
</tr>
</tfoot>
<tbody>
<tr >
<th scope=\"row\" id=\"r101\"></th>
<td></td>
<td>".$homeID."</td>
<td><strong>".$homeschool['school_name']."</strong></td>
<td><input name=\"team_radio\" type=radio value=$home /></td>
</tr>
<tr class=\"odd\">
<th scope=\"row\" id=\"r100\"></th>
<td></td>
<td>".$awayID."</td>
<td><strong>".$awayschool['school_name']."</strong></td>
<td><input name=team_radio type=radio value=$away /></td>
</tr>
</tbody>
</table>
</form>
<br />
<br />";
}
//if bet on game
else {
//if bet is from current member
if($gameinfo['member_id'] == $_SESSION['SESS_MEMBER_ID']){
continue 2;
}
else {
echo "<form id=\"betForm\" name=\"betForm\" method=post action=\"bet-exec.php\">";
$sport_event_id = $gameinfo['sport_event_id'];
$homeID = $gameinfo['home_id'];
$awayID = $gameinfo['away_id'];
$data2 = mysql_query("SELECT school_name, team_id FROM teams WHERE team_id='$homeID'")
or die(mysql_error());
$data3 = mysql_query("SELECT school_name, team_id FROM teams WHERE team_id='$awayID'")
or die(mysql_error());
$homeschool = mysql_fetch_array( $data2 );
$awayschool = mysql_fetch_array( $data3 );
$home = $homeschool['school_name'];
$away = $awayschool['school_name'];
echo "<table align=\"center\">
<thead>
<tr>
<th width=\"167\" scope=\"col\">".$gameinfo['game_date']."</th>
<th width=\"94\" scope=\"col\">".ucwords($gameinfo['sport'])."</th>
<th width=\"79\" scope=\"col\">Team ID</th>
<th width=\"216\" scope=\"col\">Teams</th>
<th width=\"70\" scope=\"col\">Selection</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope=\"row\"><input type=submit name=submit_bet value=\"Place Bet\" /></th>
<td colspan=\"4\"><input name=\"bet_amt\" type=text class=textfield id=\"bet_amt\" /></td>
<td><input name=sport_event_id type=hidden value=$sport_event_id /></td>
</tr>
</tfoot>
<tbody>
<tr >
<th scope=\"row\" id=\"r101\"></th>
<td></td>
<td>".$homeID."</td>
<td><strong>".$homeschool['school_name']."</strong></td>
<td><input name=\"team_radio\" type=radio value=$home /></td>
</tr>
<tr class=\"odd\">
<th scope=\"row\" id=\"r100\"></th>
<td></td>
<td>".$awayID."</td>
<td><strong>".$awayschool['school_name']."</strong></td>
<td><input name=team_radio type=radio value=$away /></td>
</tr>
</tbody>
</table>
</form>
<br />
<br />";
}
}
}