This topic is locked

How do I get a count

4/19/2011 8:59:40 AM
PHPRunner General questions
H
horsey_kim author

Is there a way to have a count of how many items someone selects in one field?
I have set up a field to save multiple items that the person checks (used lookup wizard and am using the checkbox feature).
If they select 5 items or 10, I like to store that number in the database.
Then I can determine what value goes in cost field. Example if they select 3 classes at $10 per class then their cost is $30 and I store that in the cost field. Been searching manual and forum, nothing found yet.
any suggestions greatly appreciated <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=16854&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
My fields would be
class (check list)

count (number of classes checked)

cost (class x count)

S
swanside 4/20/2011



Is there a way to have a count of how many items someone selects in one field?
I have set up a field to save multiple items that the person checks (used lookup wizard and am using the checkbox feature).
If they select 5 items or 10, I like to store that number in the database.
Then I can determine what value goes in cost field. Example if they select 3 classes at $10 per class then their cost is $30 and I store that in the cost field. Been searching manual and forum, nothing found yet.
any suggestions greatly appreciated <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57762&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
My fields would be
class (check list)

count (number of classes checked)

cost (class x count)


I would just do it in the SQL Query at the beginneing.
SO I would have something like

SELECT

class,

count,

class*count AS cost

FROM

table_name
Would you mean like this
http://demo.asprunner.net/pggrimes_hotmail_com/cost/items_list.php

S
swanside 4/20/2011



I would just do it in the SQL Query at the beginneing.
SO I would have something like

SELECT

class,

count,

class*count AS cost

FROM

table_name
Would you mean like this
http://demo.asprunner.net/pggrimes_hotmail_com/cost/items_list.php


Sorry, I see what you mean now, I read it as Glasses that you drink from I take it you mean class as in education?

Sorry

H
horsey_kim author 4/20/2011



Sorry, I see what you mean now, I read it as Glasses that you drink from I take it you mean class as in education?

Sorry



yes classes as education. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57771&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
Question, if I do this at sql level, in the beginning, how does it know what the count field will have? At the add screen, I need the count field to count the number of classes that were checked in the class field (multiple check box field based on lookup wizard). With that info then I can tell the cost field to calculate a total. I was going to use a snippet to add the cost field total to the database when they submit their information from the add screen.
What I need is some way for the count to happen and record during add process. Does this make sense? Sorry this is confusing, just not sure how to present what I am trying to do.

S
swanside 4/20/2011



yes classes as education. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=57772&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
Question, if I do this at sql level, in the beginning, how does it know what the count field will have? At the add screen, I need the count field to count the number of classes that were checked in the class field (multiple check box field based on lookup wizard). With that info then I can tell the cost field to calculate a total. I was going to use a snippet to add the cost field total to the database when they submit their information from the add screen.
What I need is some way for the count to happen and record during add process. Does this make sense? Sorry this is confusing, just not sure how to present what I am trying to do.


You could have a table for Classes, and in there have the topics and an active field. In the visual editor on the Active set it as a checkbox in default put a 1 in it so you would have say Maths as a class and Active would be checked, but in the database it shows as a 1. so in a way if you had three classes, you would have 1,1,1 which you could sum up to 3 and multiply that by the item cost to give you a cost. I think?

In theItems table you can have a classes field relating to the classes filed in the visual editor,

H
horsey_kim author 4/21/2011

Add screen - before record added event:
$no = count(explode(",",$values["class"]));

$values["count"] = $no;
This gave me a count after record was submitted.