0

ok.. I know how to loop through an array and get the rows to build a table across the page.... that is pretty simple... but I need help creating a table on the fly that lets me pull the values and go verticle by game.. meaing the out put would looke like this (see attached gif!)


attached is the table.. its pretty straight forward... its for a soccer team. so stats tracked on the left going down verticle... and games played going across the top...

just not sure how to make this work?

Attachments table.GIF 15.44 KB
3
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by SimonMayer
0

How about doing something like this?

<?
$game1 = array("10 mins", "period 1", "3 goals", "4 shots");
$game2 = array("5 mins", "period 2", "2 goals", "3 shots");

echo "
<table>";
for($val = 0; $val <= 3; $val++)
{
	echo "
	<tr>";
	for($ar = 1; $ar <= 2; $ar++)
	{
		echo "
		<td>
			".${"game".$ar}[$val]."
		</td>";
	}
	echo "
	</tr>";
}
echo "
</table>";
?>
0

ok just one more quick question.. I pulling via mysql... all the values... min played, ext...

so each week I will get more stats based on each the number of games played.... any help on this part, but building the table part that you sent me is perfect! that is the exact way I need it to go.. its just each week I add a game... so it becomes more complex?

0

Not sure about the exact format, dont have the database structure,
but sql query to create the arrays used to create the table is just 3(maybe 4) lines of code

<?php $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
// query here creates arrays
mysql_close($dbh); 
echo "<table>";
for($val = 0; $val <= $param1; $val++) // this would be edited to be a parameter of the count returned by the sql above so the table iterates correctly
{ 
echo " <tr>";
 for($ar = 1; $ar <= $param2; $ar++) // this would be edited to be a parameter of the count returned by the sql above so the table iterates correctly
{ 
echo "<td>".${"game".$ar}[$val]."</td>"; 
}
echo "</tr>";
}
echo " </table>";
?>

sql query creates automatically the correct number of arrays for the output html table, from the number of records in the database table

0

I am not sure that this is the most efficient way, but it is one way of doing what you're trying to achieve.
It should be fine for a small set of data, but if you are using a large data set, you would possibly want to devise a more complex set of code.

$result = mysql_query("YOUR QUERY HERE");

echo "
<table>";
for($val = 0; $val <= 3; $val++)
{
	echo "
	<tr>";
	while($row = mysql_fetch_row($result))
	{
		echo "
		<td>
			".$row[$val]."
		</td>";
	}
	echo "
	</tr>";
	mysql_data_seek($result, 0); /* this sets the result back to row zero, otherwise you wouldn't see anything beyond the first value of each array. */
}
echo "
</table>";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.