Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
Thread Tools
  #1  
Old 06-20-2009, 12:25 AM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Question 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 06-20-2009, 01:00 AM
Watdaflip's Avatar
Major General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 2,151
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 06-20-2009, 08:21 AM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Thumbs up 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 06-20-2009, 11:13 PM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Question 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 06-23-2009, 01:04 AM
Watdaflip's Avatar
Major General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 2,151
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 06-23-2009, 06:41 AM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Thumbs up 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 06-25-2009, 10:23 PM
Watdaflip's Avatar
Major General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 2,151
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 06-25-2009, 10:31 PM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Question 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old 06-30-2009, 07:30 PM
Watdaflip's Avatar
Major General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 2,151
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old 06-30-2009, 08:18 PM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Thumbs up 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old 07-01-2009, 12:55 AM
Watdaflip's Avatar
Major General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 2,151
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old 07-01-2009, 11:05 PM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Question 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old 07-02-2009, 12:34 AM
Watdaflip's Avatar
Major General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 2,151
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old 07-02-2009, 07:12 AM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Question 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old 07-02-2009, 07:29 PM
Watdaflip's Avatar
Major General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 2,151
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old 07-02-2009, 08:46 PM
Rob (SA)'s Avatar
Major
 
Join Date: Nov 2006
Location: Centurion, South Africa
Posts: 483
Thumbs up Re: Count rows to in html page

Hi,

Thanks for all that effort.

I have made a posting at www.gnjgf.co.za/watflip.php to veiw the result.

Question - can I use the number created in the "Red Table" that is 103 Zwartkops to develop another table.

What I mean is now that I have the number of entrants I want to spilt the entries into two - half to play one side of the field and the remiander naturally the other half.

The entrants would then be sorted according to the handicap 52 on one side and 51 the other.

there are other inputs that could have bearing on thi slittle exercise but first things first.

Thanks for your help
__________________
Kind Regards
Rob
www.gnjgf.co.za
www.oryan-projects.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old 07-03-2009, 02:07 AM
Watdaflip's Avatar
Major General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 2,151
Default Re: Count rows to in html page

The simplest way would be to create a page for each tournament (there are much better, more complicated ways of doing it, but I will just cover this way), that is essentially a copy of the code for the blue table. And you just change the query to be something like

$quey1="select * from _Form_Nr_3 WHERE i_wish_to_play='label for the tourney' ORDER BY `handicap` ASC "

Where the green is the exact value for a tournament as it will appear in the database, and the blue, is the correct column name for the players handicap in the database table

And then change the code to have this line before the "while" loop

$total = mysql_num_rows($query1);
$half = round($total / 2);

Finally change the "if" statement to redisplay the header to be something like

if($i == $half)

That should do it. All you have to do is create a tournament page for each of the tournaments, changing the green text above to be specific to the tourney that corresponds to the page.
__________________

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


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

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

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



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


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2005-2009 VodaHost Web Hosting Your Perfect Web Host - All Rights Reserved

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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203