> I've been asked if I can alternate the colors of the
> rows to make the report more legible.
What I usually do is something like this:
if ($colour == "blue") $colour = "red" else $colour = "blue";
Then the bit where you actually output display you use $colour to set
display attributes and
On 05:11 PM 5/10/2002 -0500, Shaun Thomas wrote:
>This could use a few tweaks.
Ok I got it now... This exhibits the behaviour I was looking for, and,
thanks to you, is much easier to read and maintain! :)))
Thanks, Shaun!
Glenn
$sPrevCompany = $sColor = '';
while ($aRow = mss
Thanks! I'll play with this!!! :)
Glenn
On 05:11 PM 5/10/2002 -0500, Shaun Thomas wrote:
>This could use a few tweaks. First off, putting mysql_num_rows in the
>actual for loop executes it every iteration. Bad. Second, consider
>giving your code some readability by returning an associative ar
On Fri, 10 May 2002, Glenn Sieb wrote:
> Thanks for all the hints--here's what my boss and I eventually came
> out with:
This could use a few tweaks. First off, putting mysql_num_rows in the
actual for loop executes it every iteration. Bad. Second, consider
giving your code some readability
"1LT John W. Holmes" wrote:
>
> Read the code again, that's what I first thought, too. He's just not
> printing multiple values for the first table cell. So if the current row has
> the same company name, just print a blank cell, then print the rest of the
> data for that row.
In the words of a
- Original Message -
From: "Robert Cummings" <[EMAIL PROTECTED]>
> Glenn Sieb wrote:
> > $cname =
(strcmp($previous,$line[0])
> > ? $line[0] : " ");
> > print (" >
BGCOLOR=#$color>\n\t$line[2]\n\t$cname\n\t$line[3]
Glenn Sieb wrote:
>
> Hey everyone!
>
> Thanks for all the hints--here's what my boss and I eventually came out with:
>
> /* ##
> ## And for every row of data we pull, we create a table row...
> ## */
> $company = 0;
>
Just another version.
the call
...
$RowColor = useColor();
...
echo '';
- Jp
At 15:46 10/05/02, you wrote:
>[snip]
>$rowcount = 0;
>while($dbrowa = mysql_fetch_object($dbseta)){
> $dbrowb = mysql_fetch_object($dbsetb);
>//change the color of alternating rows
>$rowcount ++;
>if ($row
[snip]
http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Yet even more ways to do it:
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
$bgcolor = ($i++ & 1) ? '#ff' : '#00';
}
Or more then two:
$colors = array('black','green','blue','yellow');
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
$bgcolor = $colors[$i++ % 4]
Robert Cummings wrote:
>
> The more generic approach:
>
> function getNextColour( &$lastIndex, $colourList )
> {
> return $colourList[(++$lastIndex % count( $colourList ))];
U... $lastIndex++, don't want to start on the second entry :)
Cheers,
Rob.
--
.-.
| Robert Cumm
The more generic approach:
function getNextColour( &$lastIndex, $colourList )
{
return $colourList[(++$lastIndex % count( $colourList ))];
}
$colours = array
(
'#ff',
'#00ff00',
'#ff'
);
$index = 0;
foreach( $rows as $aRow )
{
echo ''
.$aRow
.''."\n";
While everyone's kicking in ideas...
I don't think modulus (as someone else suggested) is that expensive, but I
think this is the cheapest:
$evenodd = 0;
$color[0] = '#cc';
$color[1] = '#99';
while ($row = mysql_fetch_row($st))
{
print "{$row['whatever']}";
$evenodd =
[snip]
Is there a way for me to do one of the following:
1) Test to see if $i is an even or odd number?
2) Grab more than one line from the database at a time, and just put in two
table rows at once?
[/snip]
\n");
}
elseif ($rowcount <> 1) {
print("\n");
On 02:47 AM 5/11/2002 +0800, Jason Wong wrote:
> if ($i % 2) { odd; } else { even; }
Great! Thanks, Jason :)))
One thing I love about this list... you guys are more than helpful! :)
Glenn
---
Glenn E. Sieb, System Administrator
Lumeta Corp. mailto:[EMAIL PROTECTED]
+1 732 357-3514 (V)
+
On Saturday 11 May 2002 02:45, Glenn Sieb wrote:
> Hi everyone,
>
> I have a PHP script that reads data from an MS SQL server and outputs the
> data into a table. I've been asked if I can alternate the colors of the
> rows to make the report more legible. The relevant piece of code looks
> like:
>
16 matches
Mail list logo