How to alternate background colour of rows

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Rob (SA)
    Lieutenant Colonel

    • Nov 2006
    • 586

    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.
    Kind Regards
    Rob
    www.gnjgf.co.za
    www.oryan-projects.com
  • leonbasin12
    Private

    • Jul 2009
    • 3

    #2
    Re: How to alternate background colour of rows

    good info..thanx

    Comment

    • Rob (SA)
      Lieutenant Colonel

      • Nov 2006
      • 586

      #3
      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
      Kind Regards
      Rob
      www.gnjgf.co.za
      www.oryan-projects.com

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #4
        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!

        Comment

        • Rob (SA)
          Lieutenant Colonel

          • Nov 2006
          • 586

          #5
          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
          Kind Regards
          Rob
          www.gnjgf.co.za
          www.oryan-projects.com

          Comment

          • PlayItByBeer
            Lieutenant Colonel

            • Mar 2007
            • 653

            #6
            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.
            Andrew

            sigpic

            Port Elizabeth Web Design Solutions
            Latest Release: Eastern Cape Hunting Safaris
            Work In Progress Cape Town Dietician
            BlueVoda Web Design Portfolio

            Comment

            • Rob (SA)
              Lieutenant Colonel

              • Nov 2006
              • 586

              #7
              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.
              Kind Regards
              Rob
              www.gnjgf.co.za
              www.oryan-projects.com

              Comment

              • Rob (SA)
                Lieutenant Colonel

                • Nov 2006
                • 586

                #8
                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, 06:59 PM. Reason: missing info
                Kind Regards
                Rob
                www.gnjgf.co.za
                www.oryan-projects.com

                Comment

                • navaldesign
                  General & Forum Moderator

                  • Oct 2005
                  • 12080

                  #9
                  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!

                  Comment

                  • Rob (SA)
                    Lieutenant Colonel

                    • Nov 2006
                    • 586

                    #10
                    Re: How to alternate background colour of rows

                    Hi George,

                    I have it working - thank you
                    Kind Regards
                    Rob
                    www.gnjgf.co.za
                    www.oryan-projects.com

                    Comment

                    Working...
                    X