Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternating Row Colors

Status
Not open for further replies.

xWastedMindx

Technical User
Sep 3, 2002
67
US
I'm having trouble with this.
I'm using a tutorial from Here's the link to the tutorial if you'd like to look at it yourself:
Anywhoo.. I believe I have everything correct, but I keep getting parse errors on line 85. Line 85 is the first variable declaration for $color1 = '#CCFFCC';

I don't get it.. so Here's the code I have.

Does anyone see Anything wrong?

<?php

// Begin
echo &quot;<table border='1' align='center' cellpadding='5' cellspacing='0' width='275'>
<tr><td width='160'><b>DVD Name</b></td><td><b>DVD Price</b></td></tr>&quot;;

// Define colors for the alternating rows
     $color1 = '#CCFFCC';
     $color2 = '#BFD8BC';
     $row_count = 0;


// Perform the Query
$results = mysql_query(&quot;SELECT * FROM dvd('dvdName','dvdPrice')&quot;) or die(mysql_error());

while ($row = mysql_fetch_array($results)) {

$dvdName = $row[&quot;dvdName&quot;];
$dvdPrice = $row[&quot;dvdPrice&quot;];


// Some sort of equation that makes it work
$row_color = ($row_count % 2) ? $color1 : $color2;

// Table output here
echo &quot;<tr>
<td width=&quot;110&quot; bgcolor=&quot;$row_color&quot; nowrap>$dvdName</td>
<td bgcolor=&quot;$row_color&quot;>$dvdPrice</td>
</tr>&quot;;

// Adds 1 to the row count
$row_count++;

}
// Close out your table.
    echo &quot;</table>&quot;;
?>
 
Forget it. I figured it out myself.
Since I was copy/pasting the code from the tutorial... it seems PHP is picky about indents? or maybe spacing..
Also it seems PHP doesn't like double quotes very much. I had to change all those to single quotes, for it to work correctly.

whatever the case.. it works now.

 
php is very lax on white space, including extra spaces, tabs, and sometimes even line breaks (inside double quotes)...

your problem was most likely the single quotes with a # inside it, though i dont know for sure why.
 
I always use style sheets to define the colors and I alternate between the classes

Code:
if ($j==0){
	print&quot;<tr valign=top class=color1>&quot;; 
	$j++;
	} else	{
   	print&quot;<tr valign=top class=color2>&quot;; 
	$j=0;
	}

 
Your error was here, standing out like a sore thumb. Double quotes inside an echo that used double quotes. Ooopy, eh?

Table output here
echo &quot;<tr>
<td width=&quot;110&quot; bgcolor=&quot;$row_color&quot; nowrap>$dvdName</td>
<td bgcolor=&quot;$row_color&quot;>$dvdPrice</td>
</tr>&quot;;

You know having a &quot; inside an echo &quot; will end the echo.

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
ahh, so it wasnt erroring on line 85 huh?

...&quot;but I keep getting parse errors on line 85. Line 85 is the first variable declaration for $color1 = '#CCFFCC';&quot;

this is clearly not the line that contains the error that leozack pointed out, be sure to properly read and report errors! although php does sometime give wildly misleading line numbers... heh
 
$color1 = '#CCFFCC';&quot;

Should read, I think:

$color1 = &quot;#CCFFCC&quot;;

Variable has to equal something that must be Opened (by &quot; ), Closed (by &quot; ) and then ended (by ; ).

Thats my simple understanding of it anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top