Jump to content

Sorting in a mysql_query


JJohnsenDK

Recommended Posts

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
				}
				?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

Link to comment
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.