JJohnsenDK Posted June 25, 2007 Share Posted June 25, 2007 Hey How do i say to the script that it only should loop 2 times when there is 20 rows? If you look at the code then im asking it to loop everytime it finds a player with a specific id. It works fine, it loops 20 times but i only want it to loop when season_ID equal to a specific year. I could write season_ID = '2006', but that wouldnt work because then i dont get it to loop when the year is 2005 or 2004. Any suggentions? <?php $seasonQuery = mysql_query("SELECT * FROM formation WHERE player_ID = '".$spiller."' ORDER BY season_ID DESC") or die(mysql_error()); $i = 0; while($row = mysql_fetch_array($seasonQuery)){ $i++; $newSeason = $row['season_ID']+1; ?> <tr> <td><a href="#" id="BoxTitle" onclick="playerSeason(<?php echo $team_id;?>, <?php echo $row['season_ID'];?>, <?php echo $player;?>)"><?php echo $row['season_ID']."/".$newSeason; ?></a></td> <td><?php echo get_team_name($row2['team_id']); ?></td> <td></td> <td><?=get_games($row2['player_id'], $row['season_ID']);?></td> <td><?=get_goals($row2['player_id'], $row['season_ID']);?></td> <td><?=get_yellow_card($row2['player_id'], $row['season_ID']);?></td> <td><?=get_red_card($row2['player_id'], $row['season_ID']);?></td> <td><?=get_avg_grad($row2['player_id'], $row['season_ID']);?></td> </tr> <?php } ?> Quote Link to comment Share on other sites More sharing options...
TreeNode Posted June 25, 2007 Share Posted June 25, 2007 Assign the number of rows returned from a query $total_rows = mysql_num_rows($seasonQuery); Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted June 25, 2007 Author Share Posted June 25, 2007 hmmm... would that give me 20 rows too?? Quote Link to comment Share on other sites More sharing options...
TreeNode Posted June 25, 2007 Share Posted June 25, 2007 Well, now that you have the total rows you can have your conditional-loop statement include that... I might also be confused since you seem to be asking a few different things. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted June 27, 2007 Author Share Posted June 27, 2007 anyone who can help me out on this one, plz ? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted June 27, 2007 Share Posted June 27, 2007 i am not sure i fully understand what your asking. can you explain a bit more please, you've confused me. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 27, 2007 Share Posted June 27, 2007 R u looking for pagination. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted June 27, 2007 Share Posted June 27, 2007 you could chuck a LIMIT 2 in the sql query, at the end. but i dont understand this part: If you look at the code then im asking it to loop everytime it finds a player with a specific id. It works fine, it loops 20 times but i only want it to loop when season_ID equal to a specific year. I could write season_ID = '2006', but that wouldnt work because then i dont get it to loop when the year is 2005 or 2004. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted June 27, 2007 Author Share Posted June 27, 2007 ermmm... my database looks like this: formation_id = 1 game_id = 1 player_id = 1 season_id = 2006 formation_id = 2 game_id = 2 player_id = 1 season_id = 2006 formation_id = 3 game_id = 3 player_id = 1 season_id = 2006 And so on until game_id hits 20. So im asking the database to pull out the info everytime player_id = 1... that would gives me 20 rows right? But i only want it to pull out the info everytime season_id = a specific year/season. Now that would be easy if the year/season only were 2006, but it aint, its 10 different years. The whole thing is a database which stores a football/soccer players game history. So a player could have played 20 games in 2006, 30 games in 2005 and so on. is this understandable? Quote Link to comment Share on other sites More sharing options...
drummer101 Posted June 27, 2007 Share Posted June 27, 2007 You're going to have to give us a little bit more background information. Are you querying by club, player etc?? $sql = "SELECT * FROM `dbtable` WHERE _______ = ________"; is the best I/we can do for you with the information given at the moment. Hope you can clairify a bit more. Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted June 27, 2007 Author Share Posted June 27, 2007 i wrote what i querying by i the first post? WHERE player_id = $player?? Quote Link to comment Share on other sites More sharing options...
drummer101 Posted June 27, 2007 Share Posted June 27, 2007 Please click to select year to filter by. Ctrl + click to select multiple years. <form name="season_year" action=" " method="post"> <select name="year" size="3" multiple> <option value="2000">2000</option> <option value="2001">2001</option> <option value="2002">2002</option> <option value="2003">2003</option> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">20007</option> </select> </form> $season_year = $_POST["season_year"]; $sql = "SELECT * FROM formation WHERE player_ID = " . $spiller . " AND season_ID = $season_year ORDER BY season_ID DESC"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.