PHP/Table

Associate
Joined
14 May 2008
Posts
130
Hi there, been working on a raidloot system to make things easier to manage the guild. Just wondering how i could make the box be filled with colour when it has a specified attribute i.e T1 will fill pink T2 will fill blue and get the table to allign up a bit better. What i have is
http://theroundtable.is7.co.uk/raidloot.php

Kind of started to work on the fill colour but dont think it would ahve worked the way i was thinking and then got confused, so if anyone can help out or point me in the right direction :)

Code:
<?php
require_once("class2.php");
require_once(HEADERF);

$caption = "Roster";

$text = "

<br>
 	
<style type='text/css'>
table.sample
{
	width: 900px;
	border-width: 1px 1px 1px 1px;
	border-spacing: 2px;
	border-style: none none none none;
	border-color: black black black black;
	border-collapse: collapse;
}
table.sample th
{
	width: 150px;
	border-width: 2px 2px 2px 2px;
	padding: 3px 3px 3px 3px;
	border-style: solid solid solid solid;
	border-color: rgb(198, 170, 123) rgb(198, 170, 123) rgb(198, 170, 123) rgb(198, 170, 123);
	-moz-border-radius: 0px 0px 0px 0px;
}
table.sample td
{
	width: 150px;
	border-width: 2px 2px 2px 2px;
	padding: 3px 3px 3px 3px;
	border-style: solid solid solid solid;
	border-color: rgb(198, 170, 123) rgb(198, 170, 123) rgb(198, 170, 123) rgb(198, 170, 123);
	-moz-border-radius: 0px 0px 0px 0px;
}

td.header
{
	background-color: #1f2630;
	font-weight: bold;
}

tr.T1 td
{
	color: #da64bd;
}
tr.T2 td
{
	color: #7caff6;
}

</style>
<table class='sample' >
<tr>
<td class ='header'>charname</td>
<td class ='header'>head</td>
<td class ='header'>chest</td>
<td class ='header'>belt</td>
<td class ='header'>legs</td>
<td class ='header'>boots</td>
<td class ='header'>shoulders</td>
<td class ='header'>wrists</td>
<td class ='header'>hands</td>
<td class ='header'>weapon(mh)</td>
<td class ='header'>weapon(oh)</td>
</tr>
</table>

<br>
";

function printTable($result)
{
	$headered = false;

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		if (!$headered )
		{
				$text = $text . "<table class='sample'> <tr><td class ='header'>{$row['class']}</td></tr></table>";
				$headered = true;
		}

		if ($row['head'] == "T1")
			$head = "T1";
		if ($row['head'] == "T2")
			$head = "T2";
		if ($row['chest'] == "T1")
			$chest = "T1";
		if ($row['chest'] == "T2")
			$chest = "T2";
		if ($row['belt'] == "T1")
			$belt = "T1";
		if ($row['belt'] == "T2")
			$belt = "T2";

		$text = $text . "<table class='sample'>
						<td>{$row['charname']}</td>" .
						"<td>{$row['head']}</td>" .
						"<td>{$row['chest']}</td>" .
						"<td>{$row['belt']}</td>" .
						"<td>{$row['legs']}</td>" .
						"<td>{$row['boots']}</td>" .
						"<td>{$row['shoulders']}</td>" .
						"<td>{$row['wrists']}</td>" .
						"<td>{$row['hands']}</td>" .
						"<td>{$row['weapon(mh)']}</td>" .
						"<td>{$row['weapon(of)']}</td></tr>";
	}
	if ($headered)
	{
	$text = $text . "</table><br/><br/>";
	}



	return $text;
}

$link = mysql_connect('', '', '')
	or die('Connection Failed');
mysql_select_db('') or die('Could not select database');

$query = 'SELECT * FROM raidloot WHERE class="Priest of Mitra"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Tempest of Set"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Bear Shaman"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Conqueror"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Dark Templar"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Guardian"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Barbarian"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Ranger"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Assassin"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Herald of Xotli"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Demonologist"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$query = 'SELECT * FROM raidloot WHERE class="Necromancer"';
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

$text = $text . "";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);

$caption = $tp->toHtml($caption);
$text = $tp->toHtml($text);

$ns -> tablerender($caption, $text);
require_once(FOOTERF);
?>
 
Why have all those different queries on the same table with different where's?
Are you excluding stuff, or does that cover all possible entries?
If you're excluding more stuff than you're including (and you're not going to add more stuff in the future that'll you'll want excluded) then just user WHERE NOT thing = 'thing' AND NOT otherthing = 'otherthing' etc...
Having that many queries is madness! madness I say!
 
Why have all those different queries on the same table with different where's?
Are you excluding stuff, or does that cover all possible entries?
If you're excluding more stuff than you're including (and you're not going to add more stuff in the future that'll you'll want excluded) then just user WHERE NOT thing = 'thing' AND NOT otherthing = 'otherthing' etc...
Having that many queries is madness! madness I say!

aye but wanted to have the little header for each class at the start and didnt seem to work when i used group by in a single statement
 
Could you not just pull the whole database down and order it by class ?

ie
PHP:
$query = 'SELECT * FROM raidloot ORDER BY class ASC;'
$result = mysql_query($query) or die('Query Failed');
$text = $text . printTable($result);

Pretty sure you could do it that, and then use a loop to go through the data array to output the data using a switch/case setup to colour the class headers etc.
 
Back
Top Bottom