RE: [PHP-DB] Re: Alternating rows pulled from database
I'm new to PHP, so I don't know if there are any substantive advantages in execution time to any particular method, but here's what I do (granted, I've never tried it in PHP, but I do it all the time in VBScript). $cols = array("#FF", "#EEFFEE"); for ($i=1; $i<=count(mysql_num_rows($return); $i++) echo ""; //..etc next Don't crucify me if the syntax is wrong; hopefully you get the idea. I don't have PHP with me right now, so I won't be able to test it till next week. Would this actually work in PHP? The idea being that if you put it in an array and suddenly decided that you needed more than 2 colors, you just add your colors to the array and change the modulus number. Thoughts? TIM _ l i n e a r c o n c e p t s http://www.linearconcepts.com > -Original Message- > From: Ryan Marrs [mailto:[EMAIL PROTECTED]] > I don't know if this is a better way to do it, but here's how I do it: > > $return = mysql_query("SELECT This FROM That WHERE This = That"); > Print " > For($i=1;$i<=count(mysql_num_rows($return);$i++) > If($i % 2 == 0){$color="color1";} else {$color="color2";} > > Print " ". > " $value[$i] ". > " " > ; > } > Print " " > ; > > > > Here's what I did to get alternating row colors on a results > page... I'm > not > > > sure that I follow what you are asking, but I hope this will help you: > > > > > > > > > $color_one = "dd"; > > > $color_two = "cc"; > > > $row_count = 0; > > > // SEND QUERY > > > while (row = fetch array(result)) > > > { > > > $row_color = ($row_count % 2) ? $color_one : $color_two; > > > other fields from DB > > > echo "; > > > echo ""; > > > echo data out > > > echo ""; > > > echo ""; > > > $row_count++; > > > } > > > > > > > > > This is a really simple system. It uses the modulus (%) > operator. If the > > > result of the math is even it uses color_one otherwise it uses > color_two.. > > > > > > I found it somewhere, can't remember where right now.. But at least it > works > > > and it's only a few lines of code!! > > > > > > > > > Think this would work? > > > >$rowcount = 0 > >while($forum = $db->fetch_array($query)) { > > $forumlist .= ($row_count % 2) ? > >forum($forum, "index_forum") : > >forum($forum, "index_forum2"); > > $rowcount++; > >} > > > > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Re: Alternating rows pulled from database
Whoops, error in the For statement, that should read: $return = mysql_query("SELECT This FROM That WHERE This = That"); Print " For($i=1;$i<=count(mysql_num_rows($return));$i++) If($i % 2 == 0){$color="color1";} else {$color="color2";} Print " ". " $value[$i] ". " " ; } Print " " ; Ryan Marrs Web Developer Sandler and Travis Trade Advisory Services, Inc. 248.474.7200 x 183 http://www.strtrade.com -Original Message- From: Ryan Marrs [mailto:[EMAIL PROTECTED]] Sent: Friday, November 30, 2001 9:03 AM To: 'Lee Willmann'; '[EMAIL PROTECTED]' Subject: RE: [PHP-DB] Re: Alternating rows pulled from database I don't know if this is a better way to do it, but here's how I do it: $return = mysql_query("SELECT This FROM That WHERE This = That"); Print " For($i=1;$i<=count(mysql_num_rows($return);$i++) If($i % 2 == 0){$color="color1";} else {$color="color2";} Print " ". " $value[$i] ". " " ; } Print " " ; Ryan -Original Message- From: Lee Willmann [mailto:[EMAIL PROTECTED]] Sent: Friday, November 30, 2001 10:51 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Re: Alternating rows pulled from database I guess it would since you're doing basically the same thing, just a different route. "Mrbaseball34" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] > says... > > Here's what I did to get alternating row colors on a results page... I'm not > > sure that I follow what you are asking, but I hope this will help you: > > > > > > $color_one = "dd"; > > $color_two = "cc"; > > $row_count = 0; > > // SEND QUERY > > while (row = fetch array(result)) > > { > > $row_color = ($row_count % 2) ? $color_one : $color_two; > > other fields from DB > > echo "; > > echo ""; > > echo data out > > echo ""; > > echo ""; > > $row_count++; > > } > > > > > > This is a really simple system. It uses the modulus (%) operator. If the > > result of the math is even it uses color_one otherwise it uses color_two.. > > > > I found it somewhere, can't remember where right now.. But at least it works > > and it's only a few lines of code!! > > > > > Think this would work? > >$rowcount = 0 >while($forum = $db->fetch_array($query)) { > $forumlist .= ($row_count % 2) ? >forum($forum, "index_forum") : >forum($forum, "index_forum2"); > $rowcount++; >} > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Re: Alternating rows pulled from database
I don't know if this is a better way to do it, but here's how I do it: $return = mysql_query("SELECT This FROM That WHERE This = That"); Print " For($i=1;$i<=count(mysql_num_rows($return);$i++) If($i % 2 == 0){$color="color1";} else {$color="color2";} Print " ". " $value[$i] ". " " ; } Print " " ; Ryan -Original Message- From: Lee Willmann [mailto:[EMAIL PROTECTED]] Sent: Friday, November 30, 2001 10:51 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Re: Alternating rows pulled from database I guess it would since you're doing basically the same thing, just a different route. "Mrbaseball34" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] > says... > > Here's what I did to get alternating row colors on a results page... I'm not > > sure that I follow what you are asking, but I hope this will help you: > > > > > > $color_one = "dd"; > > $color_two = "cc"; > > $row_count = 0; > > // SEND QUERY > > while (row = fetch array(result)) > > { > > $row_color = ($row_count % 2) ? $color_one : $color_two; > > other fields from DB > > echo "; > > echo ""; > > echo data out > > echo ""; > > echo ""; > > $row_count++; > > } > > > > > > This is a really simple system. It uses the modulus (%) operator. If the > > result of the math is even it uses color_one otherwise it uses color_two.. > > > > I found it somewhere, can't remember where right now.. But at least it works > > and it's only a few lines of code!! > > > > > Think this would work? > >$rowcount = 0 >while($forum = $db->fetch_array($query)) { > $forumlist .= ($row_count % 2) ? >forum($forum, "index_forum") : >forum($forum, "index_forum2"); > $rowcount++; >} > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Re: Alternating rows pulled from database
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] says... > Not knowing what else is going on here... at the > very least your row counting variable is inconsistent. > > You mention row_count (in the modulus test) and rowcount > (in the initialization and incrementation). > Typo... $rowcount = 0 while($forum = $db->fetch_array($query)) { $forumlist .= ($rowcount % 2) ? forum($forum, "index_forum") : forum($forum, "index_forum2"); $rowcount++; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Re: Alternating rows pulled from database
Not knowing what else is going on here... at the very least your row counting variable is inconsistent. You mention row_count (in the modulus test) and rowcount (in the initialization and incrementation). > -Original Message- > From: MrBaseball34 [mailto:[EMAIL PROTECTED]] > Sent: Thursday, November 29, 2001 3:34 PM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] Re: Alternating rows pulled from database > > > In article <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] > says... > > Here's what I did to get alternating row colors on a > results page... I'm not > > sure that I follow what you are asking, but I hope this > will help you: > > > > > > $color_one = "dd"; > > $color_two = "cc"; > > $row_count = 0; > > // SEND QUERY > > while (row = fetch array(result)) > > { > > $row_color = ($row_count % 2) ? $color_one : $color_two; > > other fields from DB > > echo "; > > echo ""; > > echo data out > > echo ""; > > echo ""; > > $row_count++; > > } > > > > > > This is a really simple system. It uses the modulus (%) > operator. If the > > result of the math is even it uses color_one otherwise it > uses color_two.. > > > > I found it somewhere, can't remember where right now.. But > at least it works > > and it's only a few lines of code!! > > > > > Think this would work? > >$rowcount = 0 >while($forum = $db->fetch_array($query)) { > $forumlist .= ($row_count % 2) ? >forum($forum, "index_forum") : >forum($forum, "index_forum2"); > $rowcount++; >} > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]