4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 PHP, MYSQL Question
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
thor
WebHelper
WebHelper


Joined: 10 Mar 2003
Posts: 71

PostPosted: Sat Jul 09, 2005 3:54 pm (18 years, 9 months ago) Reply with QuoteBack to Top

Hey

I am a noob to php and mysql and have created a simple database and some php files to display information from the database. I have a quick question. If i am displaying results from a mysql database via php using a mysql_fetch_array how would i go about making one row in a table have one bg colour and the next row in the table another bg colour. For example

row 1 - colour 1
row 2 - colour 2
row 3 - colour 1
row 4 - colour 2

Thanks Smile
OfflineView User's ProfileFind all posts by thorSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Jul 09, 2005 8:45 pm (18 years, 9 months ago) Reply with QuoteBack to Top

Here's the code I use for this purpose:

Code:
function row_colour () {
  if (!isset($row_colour)) {
    $row_colour = 0;
  }
  global $row_colour;
  $colour = ($row_colour++ & 1) ? 'red' : 'green';
  return $colour;
}


And I then integrate this row colour in the following way:

Code:
while( bla )
{
  echo('  <tr>
    <td style="background-color: '.row_colour().'" align="left">Bla</td>
  </tr>
');
}


However there are other ways of doing it, which are possibly slightly more efficient Smile

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.203384 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme