Count rows to in html page

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

    • Nov 2006
    • 586

    Count rows to in html page

    Hi folks,

    I have a page www.gnjgf.co.za/testconcat.php that I would like to have a script that when the page populates like it is will count the entries of player to each event and then post tha toal in a column I am building.

    There is a little bit of tweaking i also want to do there so that it looks presentable.

    any response here would be appreciated
    Kind Regards
    Rob
    www.gnjgf.co.za
    www.oryan-projects.com
  • Watdaflip
    Major General

    • Sep 2005
    • 2116

    #2
    Re: Count rows to in html page

    I'm a little confused as to what you are trying to do.

    Are you wanting the total number of rows to be displayed at the end of the table? Or the row count next to each row?

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment

    • Rob (SA)
      Lieutenant Colonel

      • Nov 2006
      • 586

      #3
      Re: Count rows to in html page

      Hi,

      When you veiw the link you will see two tables.

      The left hand table has values listed in order of tournament entered.

      The right hand table lists the tournaments.

      what I would like to happen is that an automatic count of the participants listed in the right hand table to occur and the total number thereof to be placed in the right hand table under the respective event.

      all info only comes from one MySQL table to produce the veiws of infromation seen on the link page.

      I hope this helps
      Kind Regards
      Rob
      www.gnjgf.co.za
      www.oryan-projects.com

      Comment

      • Rob (SA)
        Lieutenant Colonel

        • Nov 2006
        • 586

        #4
        Re: Count rows to in html page

        Hi folks,

        So far so good - I have managed to get the page to reflect as can be seen at www.gnjgf.co.za/testconcat.php

        I how ever still require the assitance.

        I can count the rows of the table seen on the left of the page and present that total in the table on the right - in the shaded grey block.

        However this total reflects all the rows and not all the rows specific to the tournament.

        I am sure there is a clever one amoung us to solve this problem.

        I look forward to your replies.
        Kind Regards
        Rob
        www.gnjgf.co.za
        www.oryan-projects.com

        Comment

        • Watdaflip
          Major General

          • Sep 2005
          • 2116

          #5
          Re: Count rows to in html page

          I would do this by creating a variable that will be an array holding the counts for each array

          $counter = array();

          And then in the loop of all the rows add this line

          $counter[$row['tournament_column_label']]++;

          Where tournament_column_label is the column in the database for what tournament the player is in.

          And then in the column on the right just echo the counter for each tournament
          <?=$counter['tournament_label']?>

          This of course will require the values for that column to be stardardized. It has to be exactly the same for each row that are in the same tournament. If they are different they would be considered different.

          Also the order of execution of the php code will matter, the table with all of the results has to be executed first. If these are in html element in BV, I would imagine you would send this box to the back (or atleast back in order of the html box with the counts). This logic for this should follow the same as it does for forms, and getting the order when you tab to the next field to be the field directly below. If that makes sense

          Register/Login Script
          Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

          Comment

          • Rob (SA)
            Lieutenant Colonel

            • Nov 2006
            • 586

            #6
            Re: Count rows to in html page

            Hi,

            Thanks for the reply.

            This is what I have currently that gives me the total rows so far for the entire table rather than split it as you have described.

            <! THIS SECTION FETCHES THE INFORMATION FROM THE TABLE >
            <!-------------------------------------------------------------------------------->
            <?php
            while($row=mysql_fetch_array($result)){
            $string = $last_wish_to_play;
            // the first n words to extract
            $n = 4;
            // extract the words
            $words = explode(" ", $string);
            // chop the words array down to the first n elements
            $firstN = array_slice($words, 1, $n-1);
            // glue the 3 elements back into a spaced sentence
            $firstNAsAString = implode(" ", $firstN);
            // display it $firstNAsAString
            //----------------------------------------------------------------------------------------------------
            // THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED
            //----------------------------------------------------------------------------------------------------
            if($i > 0 AND $row['i_wish_to_play'] != $last_wish_to_play)
            {
            }
            //------------------------------------------------------
            // THIS SECTION ADDS HEADINGS
            //------------------------------------------------------
            if ($row['i_wish_to_play'] != $last_wish_to_play) {
            echo '<tr>
            <td align="center" bgcolor="#D6D6D8"><font style="font-size:12px" color="#00008B" face="Arial"><b>'.mysql_num_rows($result).'</b></font></td>
            <td colspan="2" align="center" bgcolor="#FFFFFF"><font style="font-size:11px" color="#00008B" face="Arial">'.$firstNAsAString.'</font></td>
            </tr>';
            }
            $last_wish_to_play = $row['i_wish_to_play'];
            $i++;
            echo '</td></tr>';
            }
            echo '</table>';
            ?>


            The part that is in red is currently giving me the total rows for each event.

            The table has been sorted and the part that it prints is not what you currently see. It is in other words as you suggest. The part of the rows that are sorted have exactly the same data which is actually seen although only once at the split in each table. (i.e @ Zwartkops Golf Club . . . . .)

            I hope this makes more sense and that you will be able to advise where I am making my mistakes to an improved result.

            Thanks for your assistance again
            Kind Regards
            Rob
            www.gnjgf.co.za
            www.oryan-projects.com

            Comment

            • Watdaflip
              Major General

              • Sep 2005
              • 2116

              #7
              Re: Count rows to in html page

              What is the code you are using for the left column, the complete list of all the golfers?

              Basically the problem is your are just printing the total number of selected rows (for all the tournaments combined). You have two options. One is to keep a tally of the number of players for each tournament as you loop through the list of all the golfers.

              The second is to have a query for each of the tournaments, checking how many golfers are in each one.

              The first option is much more efficient and quicker to do. You already have to select all of the data anyway, there is no point in doing it again in smaller groups, later on. Reading/writing are generally the most system intensive parts of a script (writing more then reading).

              Register/Login Script
              Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

              Comment

              • Rob (SA)
                Lieutenant Colonel

                • Nov 2006
                • 586

                #8
                Re: Count rows to in html page

                Hi,

                Thanks for the reply.

                The first option is what I am looking for where it lists the total amount of players entering each tournament. Each player enters various events and this is identified in the field "i_wish_to_play"

                This count is also important in that in a later part of my planning this same number is to be divided into two. First half to be "First Tee" Players and the second half "10th Tee" players.

                I hope this helps
                Kind Regards
                Rob
                www.gnjgf.co.za
                www.oryan-projects.com

                Comment

                • Watdaflip
                  Major General

                  • Sep 2005
                  • 2116

                  #9
                  Re: Count rows to in html page

                  What is the php code you are using for the left column (the complete list of players)

                  Register/Login Script
                  Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

                  Comment

                  • Rob (SA)
                    Lieutenant Colonel

                    • Nov 2006
                    • 586

                    #10
                    Re: Count rows to in html page

                    Hi,

                    The left column and the right column are listed below - I I am understanding you correctly
                    Kind Regards
                    Rob
                    www.gnjgf.co.za
                    www.oryan-projects.com

                    Comment

                    • Watdaflip
                      Major General

                      • Sep 2005
                      • 2116

                      #11
                      Re: Count rows to in html page

                      The code from ~5 posts above is the right column. It will be different from the code for the left column which lists everything in your database table

                      Register/Login Script
                      Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

                      Comment

                      • Rob (SA)
                        Lieutenant Colonel

                        • Nov 2006
                        • 586

                        #12
                        Re: Count rows to in html page

                        Hi,

                        I have copied all of the file except the login info to this page.

                        If there is something else I should do please let me know - I dont know php and thus cannnot make suggestions or propose ideas.
                        Kind Regards
                        Rob
                        www.gnjgf.co.za
                        www.oryan-projects.com

                        Comment

                        • Watdaflip
                          Major General

                          • Sep 2005
                          • 2116

                          #13
                          Re: Count rows to in html page

                          If you look at this screenshot, the script you have posted above cannot produce both the table in the blue box, as well as the table in the red box.

                          I need the code for the blue box.

                          Register/Login Script
                          Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

                          Comment

                          • Rob (SA)
                            Lieutenant Colonel

                            • Nov 2006
                            • 586

                            #14
                            Re: Count rows to in html page

                            Hi,

                            Thanks for making that clear for me.

                            I have been requesting help on the "red" side and thought you were refering to the left and right hand columns in that table.

                            I herewith post the info requested below.

                            $quey1="select * from _Form_Nr_3 ORDER BY `i_wish_to_play` ASC, `surname` ASC ";
                            $result=mysql_query($quey1) or die(mysql_error());
                            ?>
                            <!------------------------------------------------------------------>
                            <! THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE >
                            <!------------------------------------------------------------------>
                            <table border=5 width="85%" style="font-size:11px" cellspacing=0>
                            <!------------------------------------------------------------------>
                            <! THIS SECTION CHANGES THE MAIN HEADING >
                            <!------------------------------------------------------------------>
                            <caption><b><font style="font-size:16px" color="#00008B" face="Arial">
                            </font><b><caption>
                            <!------------------------------------------------------------------->
                            <! THIS SECTION FETCHES THE INFORMATION FROM THE TABLE >
                            <!------------------------------------------------------------------->
                            <?php
                            while($row=mysql_fetch_array($result)){
                            //----------------------------------------------------------------------------------------------------
                            // THIS SECTION ADDS 1 EMPTY LINE IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED
                            //----------------------------------------------------------------------------------------------------
                            if($i > 0 AND $row['i_wish_to_play'] != $last_wish_to_play){
                            echo '<tr>
                            <td colspan="3">&nbsp;</td>
                            </tr>';
                            }
                            //------------------------------------------------------
                            // THIS SECTION ADDS HEADINGS
                            //------------------------------------------------------
                            if ($row['i_wish_to_play'] != $last_wish_to_play) {
                            echo '<tr>
                            <td colspan="3" align="center" bgcolor="#FFFFFF"><font style="font-size:11px" color="#00008B" face="Arial"><b>'.$row['i_wish_to_play'].'</b></font></td>
                            </tr>';
                            echo '<tr>
                            <td bgcolor="#D6D6D8"><font style="font-size:11px" color="#00008B" face="Arial"><b>FULL NAME</b></font></td>
                            <td align="center" bgcolor="#D6D6D8"><font style="font-size:11px" color="#00008B" face="Arial"><b>HANDICAP</b></font></td>
                            <td align="center" bgcolor="#D6D6D8"><font style="font-size:11px" color="#00008B" face="Arial"><b>CELL NUMBER</b></font></td>
                            </tr>';
                            }
                            echo '<tr><td bgcolor="#FFFFFF">';
                            echo '<option value="'.$row['surname'].', '.$row['name'].'">'.$row['surname'].', '.$row['name'].'</option>';
                            echo '</td><td align="center" bgcolor="#FFFFFF">';
                            echo $row['my_handicap_is'];
                            echo '</td><td align="center" bgcolor="#FFFFFF">';
                            echo $row['cell_phone'];
                            $last_wish_to_play = $row['i_wish_to_play'];
                            $i++;
                            echo '</td></tr>';
                            }
                            echo '</table>';
                            ?>
                            Kind Regards
                            Rob
                            www.gnjgf.co.za
                            www.oryan-projects.com

                            Comment

                            • Watdaflip
                              Major General

                              • Sep 2005
                              • 2116

                              #15
                              Re: Count rows to in html page

                              Alright update the blue table with this code (note I didn't test it so there could be some sort of error, back up what you are using now before you change it).

                              PHP Code:
                              <?php
                              $quey1
                              ="select * from _Form_Nr_3 ORDER BY `i_wish_to_play` ASC, `surname` ASC ";
                              $result=mysql_query($quey1) or die(mysql_error());
                              ?>
                              <!------------------------------------------------------------------>
                              <!           THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE         >
                              <!------------------------------------------------------------------>
                              <table border=5 width="85%" style="font-size:11px" cellspacing=0>
                              <!------------------------------------------------------------------>
                              <!                  THIS SECTION CHANGES THE MAIN HEADING           > 
                              <!------------------------------------------------------------------>
                              <caption><b><font style="font-size:16px" color="#00008B" face="Arial">
                              </font><b><caption>
                              <!------------------------------------------------------------------->
                              <!          THIS SECTION FETCHES THE INFORMATION FROM THE TABLE      >  
                              <!------------------------------------------------------------------->
                              <?php
                              $counter 
                              = array();
                              $last_wish_to_play "";
                              $firstNAsAString "";
                              while(
                              $row=mysql_fetch_array($result)){
                              //----------------------------------------------------------------------------------------------------
                              // THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED
                              //----------------------------------------------------------------------------------------------------
                              if($i AND $row['i_wish_to_play'] != $last_wish_to_play){
                              echo 
                              '<tr>
                              <td colspan="3">&nbsp;</td>
                              </tr>'
                              ;
                              }
                              //------------------------------------------------------
                              //            THIS SECTION ADDS HEADINGS                
                              //------------------------------------------------------
                              if ($row['i_wish_to_play'] != $last_wish_to_play) {
                              echo 
                              '<tr>
                              <td colspan="3" align="center" bgcolor="#FFFFFF"><font style="font-size:11px" color="#00008B" face="Arial"><b>'
                              .$row['i_wish_to_play'].'</b></font></td>
                              </tr>'
                              ;
                              echo 
                              '<tr>
                              <td bgcolor="#D6D6D8"><font style="font-size:11px" color="#00008B" face="Arial"><b>FULL NAME</b></font></td>
                              <td align="center" bgcolor="#D6D6D8"><font style="font-size:11px" color="#00008B" face="Arial"><b>HANDICAP</b></font></td>
                              <td align="center" bgcolor="#D6D6D8"><font style="font-size:11px" color="#00008B" face="Arial"><b>CELL NUMBER</b></font></td>
                              </tr>'
                              ;
                              }
                              echo 
                              '<tr><td bgcolor="#FFFFFF">';
                              echo 
                              '<option value="'.$row['surname'].', '.$row['name'].'">'.$row['surname'].', '.$row['name'].'</option>';
                              echo 
                              '</td><td align="center" bgcolor="#FFFFFF">';
                              echo 
                              $row['my_handicap_is'];
                              echo 
                              '</td><td align="center" bgcolor="#FFFFFF">';
                              echo 
                              $row['cell_phone'];
                              if(
                              $row['i_wish_to_play'] != $last_wish_to_play)
                              {
                              // the first n words to extract
                              $n 4;
                              // extract the words
                              $words explode(" "$row['i_wish_to_play']);
                              // chop the words array down to the first n elements
                              $firstN array_slice($words1$n-1);
                              // glue the 3 elements back into a spaced sentence
                              $firstNAsAString implode(" "$firstN);
                              }
                              if(!isset(
                              $counter[$firstNAsAString]))
                              $counter[$firstNAsAString] = 0;
                              else
                              $counter[$firstNAsAString]++;
                               
                              $last_wish_to_play $row['i_wish_to_play'];

                              $i++;
                               echo 
                              '</td></tr>';
                              }
                              echo 
                              '</table>';
                              ?>
                              And then replace the code for the red box with this

                              PHP Code:
                              <!          THIS SECTION FETCHES THE INFORMATION FROM THE TABLE      >  
                              <!-------------------------------------------------------------------------------->
                              <?php
                              echo '<table>';
                              foreach(
                              $counter as $key => $value)
                              {
                              echo 
                              '<tr>
                              <td align="center" bgcolor="#D6D6D8"><font style="font-size:12px" color="#00008B" face="Arial"><b>'
                              .$value.'</b></font></td>
                              <td colspan="2" align="center" bgcolor="#FFFFFF"><font style="font-size:11px" color="#00008B" face="Arial">'
                              .$key.'</font></td>
                              </tr>'
                              ;
                              }
                              echo 
                              '</table>';
                              ?>

                              Register/Login Script
                              Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

                              Comment

                              Working...