473,512 Members | 15,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple rows and alternate color

Below I found a code to make multiple colums from the output of a DB, how
can I incorporate alternat colors to the multiple row snippet?

<?php
//set the number of columns
$columns = 2;

mysql_connect('localhost','','');
mysql_select_db('test');
$query = "SELECT stuff FROM mystuff ORDER BY stuff";
$result = mysql_query($query);

//we add this line because we need to know the number of rows
$num_rows = mysql_num_rows($result);
echo "<TABLE BORDER=\"0\">\n";

//changed this to a for loop so we can use the number of rows
for($i = 0; $i < $num_rows; $i++) {
$row = mysql_fetch_array($result);
if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
echo "<TR>\n";
}
echo "<TD>" . $row['stuff'] . "</TD>\n";
if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
echo "</TR>\n";
}
}
echo "</TABLE>\n";
?>
Jul 17 '05 #1
1 2094
aznFETISH wrote:
Below I found a code to make multiple colums from the output of a DB, how
can I incorporate alternat colors to the multiple row snippet?

<?php
//set the number of columns
$columns = 2;

....

This is a really tedious way of doing things. Have a look at
HTML_Table package from PEAR. Alternating row colors is just one line
into your code. Something like this (given that $t is a HTML_Table):

....
$light = array('bgcolor' => '#CCCCCC');
$dark = array('bgcolor' => '#AAAAAA');
$t->altRowAttributes(1,$light,$dark,TRUE);
....

/Marcin
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3429
by: Paolo | last post by:
Hi to all, could you please help me with this issue? I'd like to have the rows of a VB6 ADO grid bound to a db painted with an alternate background and foreground colors. I'd like to have the odd...
4
75830
by: Raj Kotaru | last post by:
Hi, In sqlplus, I can insert a single row using: insert into employee (name, salary, hiredate) values ('xyz', '86378', sysdate); Is there a modification of the insert command that will...
4
3777
by: steve | last post by:
I'm new to XML, so pardon the stupid question. I've looked thru several books with not luck. All I want to do is associate one xml file with multiple xsl stylesheets. For example, if the user...
5
6416
by: Matt | last post by:
I want to produce colors in alternate rows in the table. The following will produce blue color on every row. So my problem is to figure out to count the records. If it is odd record, then do <tr...
14
2570
by: Jacqui or (maybe) Pete | last post by:
Having just answered a question about multiple linked stylesheets, I thought I'd have a look at browser support. There's a quick test page here: http://www.porjes.com/ms/ I wrote it...
0
1108
by: Richard Huxton | last post by:
The interaction of rules with views can be complicated, so here's a short sample file which illustrates the main points. -- Richard Huxton Archonet Ltd === BEGIN rule_test.sql === DROP...
11
2711
by: windandwaves | last post by:
Hi Gurus Is there a way to accentuate even or uneven rows in a table or list? TIA - Nicolaas
2
1808
by: probashi | last post by:
Hi, Instead of alternating style row by row is it possible to alternate style for group of rows: For example I am displaying all the employee information in a grid view sorted by department....
2
1428
cameokid
by: cameokid | last post by:
Hi, Here is the problem which i am facing. I am trying to delete rows (using nodes) containing XML data. I am doing this to add new set of data from XML file by using a dropdown selection. ...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.