Jump to content

Recommended Posts

I am trying to add some new information to an existing web page. I added the loop but it breaks after the first result. Any help would be appreciated.
[code]include("header.php");
require_once("mainfile.php");
$index=1;
echo "<table align=center>";
$id = Array();
$team = Array();
$name = Array();
$position = Array();
$type = Array();
$length = Array();
//Get max season
$season_sql = "Select max(season) from team_schedule where league_id='1'";
$season =  mysql_query($season_sql);
$season_num = mysql_fetch_array($season);
$max_season = $season_num['max(season)'];
//$db = @mysql_connect($dbhost,$dbuname,$dbpass);
//@mysql_select_db($dbname,$db);
$injury_query = "SELECT * FROM madcat_yearly_player_info WHERE injured='yes' and year='$max_season'";
$i = 0;
$injury_results = mysql_query($injury_query) or die(mysql_error());
while($result = mysql_fetch_array($injury_results)) {
$i++;
$current_player_id = $result['id'];
$current_team = $result['team'];
$player_query = "SELECT * FROM madcat_players WHERE id='$current_player_id'";
$player_results = mysql_query($player_query) or die(mysql_error());
while($result2=mysql_fetch_array($player_results)){
$player_name = $result2['name'];
$player_pos = $result2['pos'];
$id[$i] = $current_player_id;
$team[$i] = strtolower($current_team);
$name[$i] = $player_name;
$position[$i] = $player_pos;
$injury_query = "SELECT * FROM weekly_injuries WHERE player_name='$name[$i]'";
$injury_results = mysql_query($injury_query) or die (mysql_error());
while($result1=mysql_fetch_array($injury_results)){
$injury_type = $result1['injury_type'];
$injury_length = $result1['injury_length'];
$type[$i] = $injury_type;
$length[$i] = $injury_length;
echo "<tr><td align=center class=injuryreport><img src=../../images/smalllogos/{$team[$i]}.gif></td><td align=center class=injuryreport>{$position[$i]}</td><td align-center class=injuryreport>{$name[$i]}</td><td align=center class=injuryreport>{$type[$i]}</td><td align=center class=injuryreport>{$length[$i]}</td></tr>";
}
}
}

echo "</table>";
include("footer.php");[/code]

Here is exactly what I added to the above script when it broke.
[code]$injury_query = "SELECT * FROM weekly_injuries WHERE player_name='$name[$i]'";
$injury_results = mysql_query($injury_query) or die (mysql_error());
while($result1=mysql_fetch_array($injury_results)){
$injury_type = $result1['injury_type'];
$injury_length = $result1['injury_length'];
$type[$i] = $injury_type;
$length[$i] = $injury_length;
echo "<tr><td align=center class=injuryreport><img src=../../images/smalllogos/{$team[$i]}.gif></td><td align=center class=injuryreport>{$position[$i]}</td><td align-center class=injuryreport>{$name[$i]}</td><td align=center class=injuryreport>{$type[$i]}</td><td align=center class=injuryreport>{$length[$i]}</td></tr>";
}
[/code]
In the echo I just added the variables. Again any help would be greatly appreciated.
Link to comment
https://forums.phpfreaks.com/topic/13801-loop-breaks-when-i-add-some-new-code/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.