Results 1 to 10 of 10

Thread: How to alternate background colour of rows
      
   

  1. #1
    Rob (SA)'s Avatar
    Rob (SA) is offline Lieutenant Colonel
    Join Date
    Nov 2006
    Location
    Centurion, South Africa
    Posts
    580

    Question How to alternate background colour of rows

    Hi Folks,

    We have managed to gather the data from MySQL to veiw as seen at www.gnjgf.co.za/watflip.php

    I would however like to create the option of perhaps showing the data as I can show from the link at http://uploads.saga.co.za/rankings/rateindx.htm

    The rows alternate in colour.

    If there is someone out there who can help I look forward to your replies.

  2. #2
    leonbasin12 is offline Private
    Join Date
    Jul 2009
    Location
    FRANCE
    Posts
    3

    Default Re: How to alternate background colour of rows

    good info..thanx

  3. #3
    Rob (SA)'s Avatar
    Rob (SA) is offline Lieutenant Colonel
    Join Date
    Nov 2006
    Location
    Centurion, South Africa
    Posts
    580

    Question Re: How to alternate background colour of rows

    Hi Folks,

    In my efforts to get this to work - I am now receiveing an error:

    Fatal error: Call to undefined function row_color() in /home/******/public_html/gnjgf/watflip.php on line 111

    I would appreciate it if someone could help in this regard

  4. #4
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: How to alternate background colour of rows

    I can't know what you have done, as you seem to be calling a non defined function.

    Anyway, there are also very simple ways to do this directly in your table <td> definition.

    You add a counter ($i) which autoincrements by 1 for each row.
    Then you add this code (just an example):

    $bgcolor1 = "#222224";
    $bgcolor2 = "#808080";
    $bgcolor = $bgcolor1;
    if($i%2 == "0"){
    $bgcolor = $bgcolor2;
    }


    And in your <td> definition you add this:

    echo '....your code

    <td bgcolor="'.$bgcolor.'"> rest of cel code....

    ... rest of code....
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  5. #5
    Rob (SA)'s Avatar
    Rob (SA) is offline Lieutenant Colonel
    Join Date
    Nov 2006
    Location
    Centurion, South Africa
    Posts
    580

    Thumbs up Re: How to alternate background colour of rows

    Hi George,

    Thanks for the info - I will have a look at it and see if I can get it to work better.

    My big difficulty is identifying exactly where to place this info.

    Let me try and if I get stuck I will post agian

  6. #6
    PlayItByBeer's Avatar
    PlayItByBeer is offline Lieutenant Colonel
    Join Date
    Mar 2007
    Location
    Port Elizabeth, South Africa
    Posts
    653

    Default Re: How to alternate background colour of rows

    Hi Rob,

    Just to throw a spanner in the works but i know you are busy with the script. Are you not openning yourself up to member complaints, by showing their contact details... it's an online golfers database now. LOL

    We seem to get enough calls from telesales people who always call at the wrong time in SA.

  7. #7
    Rob (SA)'s Avatar
    Rob (SA) is offline Lieutenant Colonel
    Join Date
    Nov 2006
    Location
    Centurion, South Africa
    Posts
    580

    Thumbs up Re: How to alternate background colour of rows

    Hi Andrew,

    Your sentiments are exactly the same as mine and I agree with you whole heartedly.

    This page is my test page and once complete you will need to use a login to access. The page name will also be changing to be included to the site better and other applications that will be coming.

    My php skills being very limited the process is extremly slow - I not complaining - i am learning

    Hope all is well down there.

  8. #8
    Rob (SA)'s Avatar
    Rob (SA) is offline Lieutenant Colonel
    Join Date
    Nov 2006
    Location
    Centurion, South Africa
    Posts
    580

    Question Re: How to alternate background colour of rows

    Hi George,

    I have found this text which seems to be similar:
    <?php

    $color1="#FFFFCC"; //First Colour
    $color2="none"; // Second Colour
    $row_count=0; //Set row_count to 0
    while($m=mysql_fetch_array($quey1)) //SQL query
    {
    $row_count++;//Counts row_count
    $row_color = ($row_count % 2) ? $color1 : $color2; //Gets the colour to be used
    print "<tr style='background:{$row_color}'> //Sets the row colour.
    }

    If so where would I insert it.

    I have tried your method but dont get any where near the required result.

    Any other views would be most welcome
    Last edited by Rob (SA); 07-17-2009 at 06:59 PM. Reason: missing info

  9. #9
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: How to alternate background colour of rows

    Rob, it depends on the rest of your code, how can i ever know it ?

    Usually the first part (the two colors definition) goes before the loop, the counter part (i said $i, you say $row_count, the concept is the same) goes before or immediately after the <table> definition:

    code................
    $bgcolor1 = "#222224";
    $bgcolor2 = "#808080";
    echo'
    <table id=.......... etc>';
    while(....loop){
    $bgcolor = $bgcolor1;
    if($i&#37;2 == "0"){
    $bgcolor = $bgcolor2;
    }
    echo '<tr>
    <td bgcolor = '.$bgcolor.'>cell content.........
    </tr>
    more <td>'s...................of the same recordset
    ';
    }
    echo '<table>';


    etc
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  10. #10
    Rob (SA)'s Avatar
    Rob (SA) is offline Lieutenant Colonel
    Join Date
    Nov 2006
    Location
    Centurion, South Africa
    Posts
    580

    Thumbs up Re: How to alternate background colour of rows

    Hi George,

    I have it working - thank you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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