Solved

Alternate Row

Posted on 2010-09-01
6
398 Views
Last Modified: 2012-05-10
<?php
$result = mysql_query("
select 
m.match_id, m.date, m.time, m.report, 
t1.team_name as team1_name, t1.team_id as team1_id, s1.score as score1, 
t2.team_name as team2_name, t2.team_id as team2_id, s2.score as score2 
from matches m 
left join (matchscores s1 left join team t1 on t1.team_id = s1.team) on (s1.match_id = m.match_id) 
left join (matchscores s2 left join team t2 on t2.team_id = s2.team) on (s2.match_id = m.match_id) 
where s1.team <> s2.team group by match_id order by m.match_id") or die(mysql_error());

while($record = mysql_fetch_assoc($result))
{
  // Check if we have already got an entry for this pair of teams, and if so, try them the other way round.
  if(!isset($resultsgrid[$record['team1_id']][$record['team2_id']]))
  {
    $resultsgrid[$record['team1_id']][$record['team2_id']] = $record['score1'].'-'.$record['score2'];
  }
  elseif(!isset($resultsgrid[$record['team2_id']][$record['team1_id']]))
  {
    $resultsgrid[$record['team2_id']][$record['team1_id']] = $record['score2'].'-'.$record['score1'];
  }
  else
  {
    // This would be the 3rd result for this pair so make an error or something.
  }
  // Also we want a list of teams for our headers
  $teams[$record['team1_id']] = $record['team1_name'];
  $teams[$record['team2_id']] = $record['team2_name'];
}

// Now output the grid as a table
$html = '
	<table width="100%" border="1">
		<tr style="background-color:#000000;"><th>&nbsp;</th>';
foreach($teams as $col=>$teamcolname)
{
	$html .= "<th >$teamcolname</th>";
}
$html .= '</tr>';
foreach($teams as $row=>$teamrowname)
{
	$html .= "
		<tr><th style=\"background-color:#eee;\">$teamrowname</th>";
	foreach($teams as $col=>$teamcolname)
	{
		if($col == $row)
		{
			$html .= '
			<td style="width: 4em; text-align: center; background-color:black;">X</td>';
		}
		else
		{
			$html .= '
			<td style="width: 4em; text-align: center; background-color:#124f16; color:#ffffff; font-weight:bold;">'.(isset($resultsgrid[$row][$col])?$resultsgrid[$row][$col]:'-').'</td>'; // If there is no result for this position, make a '-' instead.
		}
	}
	$html .= '
		</tr>';
}
$html .= '
	</table>';
echo $html;

?>

Open in new window


I have this code that I want to modify the TH's of.

The TH's hold the team name and I need alternating background colours

The Headings go along the top and the left hand side.

I have been trying to use the Dreamweaver code I have but that keeps giving errors.
Is there any other way to do it?
0
Comment
Question by:cataleptic_state
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 4

Author Comment

by:cataleptic_state
ID: 33577986
The Dreameaver code is

// Initialize the Alternate Color counter
$ac_sw1 = 0;

<tr bgcolor="<?php echo ($ac_sw1++%2==0)?"#ffffff":"#dfdfdf"; ?>" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor=''">

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 33578029
What error does the code give you?
0
 
LVL 4

Author Comment

by:cataleptic_state
ID: 33578522
I have removed it now but here is how the line looked

$html .= "<th bgcolor="echo ($ac_sw1++%2==0)?"#ffffff":"#dfdfdf";">$teamcolname</th>";

Error code:
Parse error: syntax error, unexpected T_ECHO in C:\xampp\htdocs\football\results-grid.php on line 282
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
mpickreign earned 500 total points
ID: 33580190
You have no need for the command echo in the middle of a string.

Change the line to this
$html .= "<th bgcolor=" . (($ac_sw1++%2==0)?"#ffffff":"#dfdfdf") . ">$teamcolname</th>";
0
 
LVL 5

Expert Comment

by:SaigonJeff
ID: 33584610
Here is a free extension for Dreamweaver that will create alternating row colors.

Maybe it will be of some help.

http://www.dmxzone.com/go?4717
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 33586038
Good morning.  I just woke up to find you have accepted an answer to this question, and I did not see your updates over night.  From the code posted below and the answer you accepted, I think you might benefit from a book that could give you something of a foundation in the principles of PHP.  A "parse error" is the most basic of syntax issues, kind of like not knowing what notes to play when you look at a chart of musical chords.  Maybe one day I will write an article about coding standards, but in the mean time, please go buy this book and work through the examples.  It will not make you a professional, but it is easy to read and has plenty of code samples that you can download from the book web site and modify for your own use.

http://www.sitepoint.com/books/phpmysql4/

Best of luck with your project, ~Ray
// CODE POST NUMBER ONE IS VERY DIFFERENT FROM CODE POST NUMBER TWO
$ac_sw1 = 0;
<tr bgcolor="<?php echo ($ac_sw1++%2==0)?"#ffffff":"#dfdfdf"; ?>" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor=''">

// CODE POST NUMBER TWO
$html .= "<th bgcolor="echo ($ac_sw1++%2==0)?"#ffffff":"#dfdfdf";">$teamcolname</th>";

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Obsolete font tag need to convert to CSS 3 36
warning code: class php incomplete message 6 34
Top Aligning Inner Divs 5 23
.CSS HTML Help 3 27
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question