Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > PHP
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 5:14 PM   #1
Anthony Ritter
 
Anthony Ritter's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default table output

I'm trying to output a table with alternate background color rows.

The following snippet outputs a table after connecting to a mySQL database
with posts but they all have the same bgcolor.

Any help with the syntax will be greatly appreciated.
Thank you.
Tony Ritter
.........................................
<?

<table width=100% cellpadding=3 cellspacing=1 border=1>
<tr>
<th bgcolor=\"#497fbf\"><font color=\"#ffffff\">AUTHOR</font>
</th>
<th bgcolor=\"#497fbf\"><font color=\"#ffffff\">POST</font></th>
</tr>";

while ($posts_info = mysql_fetch_array($get_posts_res)) {
$post_id = $posts_info['post_id'];
$post_text = nl2br(stripslashes($posts_info['post_text']));
$post_create_time = $posts_info['fmt_post_create_time'];
$post_owner = stripslashes($posts_info['post_owner']);

$color1 = "#CCFFCC";
$color2 = "#BFD8BC";
$posts_info = 0;
$row_color = ($posts_info % 2) ? $color1 : $color2;

//add to display
$display_block .= "
<tr>
<td width=35% valign=top
bgcolor=\"$row_color\"><p>$post_owner<br>[$post_create_time]</td>
<td width=65% valign=top bgcolor=\"$row_color\"><p>$post_text<br><br>
<a href=\"replytopost.php?post_id=$post_id\"><strong> REPLY TO
POST</strong></a></td>

</tr>";

}

//close up the table
$display_block .= "</table>";
?>





 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 07-01-2007, 5:14 PM   #2
JKD
 
JKD's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default table output

I have only been monitoring this group for 5 days now and have seen 10
questions involving alternate row colors for PHP tables. Being an
intermediate PHP programmer myself, I know that there are at least twenty
tutorials on how to accomplish this on any typical Google search by simply
typing in "PHP Alternate Row Colors". I am going to regard any question on
this topic nothing more than simple spam harvesting from now on.

GFYself

JD



"Anthony Ritter" <tony@gonefishingguideservice.com> wrote in message
news:3f42eb4d@news.greennet.net...
> I'm trying to output a table with alternate background color rows.
>
> The following snippet outputs a table after connecting to a mySQL database
> with posts but they all have the same bgcolor.
>
> Any help with the syntax will be greatly appreciated.
> Thank you.
> Tony Ritter
> ........................................
> <?
>
> <table width=100% cellpadding=3 cellspacing=1 border=1>
> <tr>
> <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">AUTHOR</font>
> </th>
> <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">POST</font></th>
> </tr>";
>
> while ($posts_info = mysql_fetch_array($get_posts_res)) {
> $post_id = $posts_info['post_id'];
> $post_text = nl2br(stripslashes($posts_info['post_text']));
> $post_create_time = $posts_info['fmt_post_create_time'];
> $post_owner = stripslashes($posts_info['post_owner']);
>
> $color1 = "#CCFFCC";
> $color2 = "#BFD8BC";
> $posts_info = 0;
> $row_color = ($posts_info % 2) ? $color1 : $color2;
>
> //add to display
> $display_block .= "
> <tr>
> <td width=35% valign=top
> bgcolor=\"$row_color\"><p>$post_owner<br>[$post_create_time]</td>
> <td width=65% valign=top

bgcolor=\"$row_color\"><p>$post_text<br><br>
> <a href=\"replytopost.php?post_id=$post_id\"><strong> REPLY TO
> POST</strong></a></td>
>
> </tr>";
>
> }
>
> //close up the table
> $display_block .= "</table>";
> ?>
>
>
>
>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 5:14 PM   #3
Tom Thackrey
 
Tom Thackrey's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default table output


On 19-Aug-2003, "JKD" <dev@null.org> wrote:

> I have only been monitoring this group for 5 days now and have seen 10
> questions involving alternate row colors for PHP tables. Being an
> intermediate PHP programmer myself, I know that there are at least twenty
> tutorials on how to accomplish this on any typical Google search by simply
> typing in "PHP Alternate Row Colors". I am going to regard any question on
> this topic nothing more than simple spam harvesting from now on.
>
> GFYself


Kinda harsh for a noobe. This question comes up a lot because there are a
lot of beginners here, not because of anything sinister. Most of us started
as beginners. :-)

The next time someone stomps on you because you asked or answered a question
poorly consider it karma.


--
Tom Thackrey
www.creative-light.com
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 5:14 PM   #4
Nikolai Chuvakhin
 
Nikolai Chuvakhin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default table output

"Anthony Ritter" <tony@gonefishingguideservice.com> wrote
in message news:<3f42eb4d@news.greennet.net>...
>
> I'm trying to output a table with alternate background color rows.
>
> The following snippet outputs a table after connecting to a mySQL
> database with posts but they all have the same bgcolor.


OK, let's look at your code:

> while ($posts_info = mysql_fetch_array($get_posts_res)) {


This means that $posts_info is an array.

> $row_color = ($posts_info % 2) ? $color1 : $color2;


But here you expect $posts_info to be a number... You are asking
PHP to convert an array into a number, which PHP can't really do,
so it tries to first convert it into a boolean (which comes out
to be TRUE, because empty arrays evaluate to FALSE, all other arrays
to TRUE), and then convert that boolean into an integer (1). The
end result: $posts_info in this expression always evaluates to 1.

Try this instead:

if ($row_color == $color1) {
$row_color = $color2;
} else {
$row_color = $color1;
}

Cheers,
NC
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 5:14 PM   #5
Tom Thackrey
 
Tom Thackrey's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default table output


On 19-Aug-2003, "Anthony Ritter" <tony@gonefishingguideservice.com> wrote:

> I'm trying to output a table with alternate background color rows.
>
> The following snippet outputs a table after connecting to a mySQL database
> with posts but they all have the same bgcolor.
>
> Any help with the syntax will be greatly appreciated.
> Thank you.
> Tony Ritter
> ........................................
> <?
>
> <table width=100% cellpadding=3 cellspacing=1 border=1>
> <tr>
> <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">AUTHOR</font>
> </th>
> <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">POST</font></th>
> </tr>";
>
> while ($posts_info = mysql_fetch_array($get_posts_res)) {
> $post_id = $posts_info['post_id'];
> $post_text = nl2br(stripslashes($posts_info['post_text']));
> $post_create_time = $posts_info['fmt_post_create_time'];
> $post_owner = stripslashes($posts_info['post_owner']);
>
> $color1 = "#CCFFCC";
> $color2 = "#BFD8BC";
> $posts_info = 0;
> $row_color = ($posts_info % 2) ? $color1 : $color2;
>
> //add to display
> $display_block .= "
> <tr>
> <td width=35% valign=top
> bgcolor=\"$row_color\"><p>$post_owner<br>[$post_create_time]</td>
> <td width=65% valign=top
> bgcolor=\"$row_color\"><p>$post_text<br><br>
> <a href=\"replytopost.php?post_id=$post_id\"><strong> REPLY TO
> POST</strong></a></td>
>
> </tr>";
>
> }
>
> //close up the table
> $display_block .= "</table>";
> ?>


You're pretty close. You can't use $posts_info to switch colors, because you
set it to 0 so it doesnt change.

Add this before the while loop:
$row_count = 0;

change the color test to:
$row_color = ($row_count % 2) ? $color1 : $color2;

add this somewhere in the loop:
$row_count ++;

You should also move the initialization of $color1 and $color2 outside the
loop or just stick the literals into the color test:
$row_color = ($row_count % 2) ? '#ccffcc' : '#bfd8bc';

--
Tom Thackrey
www.creative-light.com
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 5:23 PM   #6
Anthony Ritter
 
Anthony Ritter's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default table output

Thank you Nikolai and Tom for the clear explanations.

Best wishes...
Tony Ritter




 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem: How to create text output to a specified table? Richard HTML 6 07-01-2007 2:05 PM
HD Output Andy Middleton New Users Help And FAQ 5 06-26-2007 9:36 AM
Output? Dr. Compynei Car audio 2 06-18-2007 12:21 PM
Delete from a table using entries in temp table n00bie Database 2 06-10-2007 12:25 AM
Only output values from a table that are NOT NULL? Bill Y. Barool Database 1 05-31-2007 8:43 PM


Featured Websites




All times are GMT +1. The time now is 12:10 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98