Jump to content


Photo

Leage table help - Probably simple


  • Please log in to reply
7 replies to this topic

#1 Pythondesigns

Pythondesigns
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 October 2006 - 05:32 PM

Ok,

Im coding a league system... Each league can have multiple divisions.

Here are three tables...

leagues(id, name);

divisions(id, leagueID);

scores(id, leagueID, userID, score);

For this example lets assume that there is one league, three divisions within that league and 20 rows in the scores table.

I want to loop through and display a table for each division.

I want to order the scores table by the score field ASC. Then display them in the divisions (10 per divisions).

So in division one it has the top 10 scores.
In division two the 11-20 top scores
In division three 21-30 top scores.


Can you help me.

Thanks

#2 Pythondesigns

Pythondesigns
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 27 October 2006 - 11:34 AM

anyone?

#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 27 October 2006 - 11:38 AM

you may find the foreach or while construtcs useful along with array_multisort....

anything more and I'd just be doing it for you!
follow me on twitter @PHPsycho

#4 Pythondesigns

Pythondesigns
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 27 October 2006 - 10:11 PM

Im still confused. Perhaps an example?

#5 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 27 October 2006 - 10:23 PM

anything more and I'd just be doing it for you!


;)
PHP Ninja

#6 Pythondesigns

Pythondesigns
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 27 October 2006 - 11:14 PM

Geez,

I thought this was a PHP Help forum. Guess I was wrong  :o

#7 Pythondesigns

Pythondesigns
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 06 November 2006 - 05:11 PM

Im still looking for help on this...?

#8 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 06 November 2006 - 06:16 PM

Something like this??

<?php

$query1 = "SELECT id FROM `leagues`";
$result1 = mysql_query($query1);

while($league = mysql_fetch_array($result1))
{
	$query2 = "SELECT COUNT(*) AS num FROM `divisions`";
	$result2 = mysql_query($query2);
	$division = mysql_fetch_array($result2);
	$tables = $division['num'];
	
	$i = 0;
	while($i < $tables)
	{
		$query3 = "SELECT * FROM `scores` ORDER BY score LIMIT ".$i.","($i+10);
		$result3 = mysql_query($query3);
		echo "<table><tr><td>id</td><td>score</td></tr>\n";
		
		while($row = mysql_fetch_array($result3))
		{
			echo "<tr>";
			echo "<td>".$row['id']."</td>";
			echo "<td>".$row['score']."</td>";
			echo "</tr>";
		}
		
		echo "</table><br><br>";
		
		$i = $i + 10;
	}
}

?>

Orio.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users