displaying information as a percentage?

This is a discussion on "displaying information as a percentage?" within the PHP Forum section. This forum, and the thread "displaying information as a percentage? are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 10th, 2008, 13:18
New Member
Join Date: May 2007
Location: uk
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
displaying information as a percentage?

I am attempting to display information submitted to a database byway of checkboxes, as a percentage of the rows within that database.

So for example; if a checkbox for ‘Group1’ was ticked once while submitting 4 separate entries to the database, ‘Group1’ would then be displayed as 25% of that database.

Does anyone know how I would submit this information to the database via checkboxes and inturn, display that information as a percentage of that database?

I have managed to submit the information to the database.
But my query for extracting it as a percentage is constantly displayed as a error message.

:(
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 Jan 10th, 2008, 14:17
Junior Member
Join Date: Nov 2007
Location: Kewanee, IL
Age: 53
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: displaying information as a percentage?

Simpler to query for the totals of each 'group' and then do the calculations via php on the results. The simpler your query, the faster are your results.

That's my 2 cents :^{>
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 Jan 10th, 2008, 14:25
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: displaying information as a percentage?

Can you post your PHP code that is giving you the errors?

It shouldn't be too hard to do what you need.

Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
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 Jan 10th, 2008, 15:18
New Member
Join Date: May 2007
Location: uk
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: displaying information as a percentage?

Thanks for the response.

The following is the checkbox code for my php form which submits the information to the database fine:
...,

</tr>
<tr>
<td><p><b>Mentoring and Coaching:</b></p></td>
<td><p><input type="checkbox" name="mc1" value="1">
<?php if (isset($_POST['mc1'])) echo $_POST['mc1']; ?></p></td>
</tr>
<tr>
<td><p><b>Accredited Training for Staff:</b></p></td>
<td><p><input type="checkbox" name="sat2" value="1">
<?php if (isset($_POST['sat2'])) echo $_POST['sat2']; ?></p></td>
</tr>
<tr>
<td><p><b>Classroom Based Training:</b></p></td>
<td><p><input type="checkbox" name="cbr3" value="1">
<?php if (isset($_POST['cbr3'])) echo $_POST['cbr3']; ?></p></td>
</tr>
<tr>
<td><p><b>Development and Delivery of Training:</b></p></td>
<td><p><input type="checkbox" name="ddt4" value="1">
<?php if (isset($_POST['ddt4'])) echo $_POST['ddt4']; ?></p></td>
</tr>
<tr>

...,

My query for extracting the code as a percentage of the database is:

$query = "(SELECT * FROM yourl_titles ORDER BY Rand()*1/percentage)LIMIT 1)";

The message I receive is 'Couldn't execute query'

???????
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 Jan 10th, 2008, 15:34
Junior Member
Join Date: Nov 2007
Location: Kewanee, IL
Age: 53
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: displaying information as a percentage?

Quote:
Originally Posted by ziggi View Post
$query = "(SELECT * FROM yourl_titles ORDER BY Rand()*1/percentage)LIMIT 1)";

The message I receive is 'Couldn't execute query'

???????

If you cut 'n paste this line, you're missing a left parenthesis or have an unneeded right one
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 Jan 10th, 2008, 15:44
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: displaying information as a percentage?

If you want to select using MySQL you have to so something like

Code: Select all
SELECT RAND()*1/percentage AS number FROM yourl_titles
But I don't actually understand what you want from the database....or what rows there are..

If you want to display as a total using PHP, you need to use something like

PHP: Select all



$result 
mysql_query("SELECT * FROM yourl_titles");
$numbers = array();
while (
$row mysql_fetch_enum($result))
    
$numbers[] = $row['whatevertherownamesare']


$total array_sum($numbers);

foreach (
$numbers as $number)
   echo  (
$number/$total*100), '%<br />'
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
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

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 On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Document Information ClaireB Classic ASP 0 Oct 24th, 2006 17:46
Erratic widths of percentage-based columns in IE psyche Web Page Design 4 Aug 13th, 2006 09:43
Working out Percentage jwalker80 JavaScript Forum 3 Jun 10th, 2006 16:29
Percentage problems HOYS Web Page Design 7 Jan 31st, 2006 15:37


All times are GMT. The time now is 15:38.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : 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