Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-15-2008, 04:00 PM Mysql Data Sorting
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I have a database full of data.

Example:

Home Team - Away Team
1 - 2
1 - 3
1 - 4
2 - 1
2 - 3
2 - 4
3 - 1
3 - 2
3 - 4


Is it possible to select from the database 2 games where the number one, two, three and four only appear once?
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 02-15-2008, 05:31 PM Re: Mysql Data Sorting
Mattmaul1992's Avatar
Ultra Talker

Posts: 486
Name: Matt
Trades: -1
Can you re-explain this?.. I don't really understand what you're saying..
EDIT: K, I thought it through. So basically you want two games to be selected and then 1, 2, 3, and 4 to appear once through all 4 numbers of the two games?
If so you can simply loop through your MySQL result and select a game with 1-2 then 3-4. Another less buggy way to do it would be to create an array with all numbers then when you use one game you set the two numbers in that game to 1 or true. Then next time it loops it checks if that game has numbers that are set false in that array. If it does then you use that game.
The only way to really do this straight in the query is to do something like this -
SELECT * FROM games WHERE score='2,1' OR score='4,3'
But that's error prone and pointless when you could use the first two options.
__________________
PHP Code:
$talkupation++; 

Please login or register to view this content. Registration is FREE
- Free IPB forum hosting (releasing today!!!), no ads, free modifications

Last edited by Mattmaul1992; 02-15-2008 at 05:50 PM..
Mattmaul1992 is offline
Reply With Quote
View Public Profile
 
Old 02-15-2008, 05:48 PM Re: Mysql Data Sorting
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
Right basically i have a list of 20 teams who i wish to sort into fixtures. I need to give each match and match_day 0 , 1 , 2 etc and so on. But each team can only play once on the same day. This code here generators all fixtures for each team but i cannot get it to give the match a match day. When i do i end up with loads teams playing on the same day.

Each team will play one home game and one away game against each team.

PHP Code:
function generate_fixtures($league_id)
{
$match_date 0;
$teams mysql_query("SELECT * FROM `manager__teams` WHERE `league` = '$league_id' LIMIT 20");
while(
$row mysql_fetch_row($teams)) {
$myArray[$row[0]] = $row[1];
}
// $key = Team Id
// $value = Team Name
while(list($key,$value) = each($myArray)) {

$allowed mysql_query("SELECT * FROM `manager__teams` WHERE `league` = '$league_id' ORDER BY RAND()");
while(
$row2 mysql_fetch_array($allowed))
{
$fixtures mysql_num_rows(mysql_query("SELECT * FROM `manager__fixtures` WHERE `league` = '$league_id' && `match_day` = '0' && `home_team` = '$value' && `away_team` = '" $row2['team'] . "'"));
if(
$fixtures == && $row2['id'] != $key)
{
mysql_query("INSERT INTO `manager__fixtures` ( `id` , `home_team` , `away_team` , `date` , `type`, `league`, `match_day` ) VALUES ('', '$key', '" $row2['id'] . "', '$match_date', 'League', '$league_id', '$match_day')");
}
}
}
$check mysql_query("SELECT * FROM `manager__teams` WHERE `league` = '$league_id' LIMIT 20");
while(
$check2 mysql_fetch_array($check))
{
$home_games mysql_num_rows(mysql_query("SELECT * FROM `manager__fixtures` WHERE `home_team` = '" $check2['id'] . "'"));
$away_games mysql_num_rows(mysql_query("SELECT * FROM `manager__fixtures` WHERE `away_team` = '" $check2['id'] . "'"));
echo 
"<strong>ID:</strong> " $check2['id'] . " : <strong>Team:</strong> " $check2['team'] . " <strong>Home Games:</strong> $home_games <strong>Away Games:</strong> $away_games<br />";
}
}

echo 
generate_fixtures("2"); 
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Reply     « Reply to Mysql Data Sorting
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14285 seconds with 12 queries