phpnewbie112 Posted November 13, 2007 Share Posted November 13, 2007 Hi everyone, I am new to php and I was trying hard to alter an existing script ut I didn't succeed to... I have 2 databases: - Categories (catid, shortname, description) - Transactions (date, amount, balance, user) in the categories I have 9 categories. the script displays the categories as checkboxes to choose from. I want to add the following functionality: If I select for example 3 categories, I would like to know how can I count the selected checkboxes and based on the count update the transactions database: in another way: if count=3 => add amount x 3 to the transactions database so if a user select 4 categories I update the transaction database with $5 x 4 categories and then we will get a balance of $20 for the choosen categories. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 13, 2007 Share Posted November 13, 2007 if you name the checkboxes in array fashion (name="chkbox[]") you can then use.. $checked = count($_POST['chkbox']); use print_r($_POST['chkbox']) to get a visual display of what has been selected.... Quote Link to comment Share on other sites More sharing options...
phpnewbie112 Posted November 13, 2007 Author Share Posted November 13, 2007 If I choose 2 categories now I have the following output (with duplicates): Array ( [0] => Category1[1] => Category2 ) Array ( [0] => Category1 [1] => Category2 ) Quote Link to comment Share on other sites More sharing options...
phpnewbie112 Posted November 13, 2007 Author Share Posted November 13, 2007 I fixed the duplicates issue. If I select 6 categories I have an output with 6 which is good. When I came back to this page, it shows the existing choosed 6, so now if I re-select 2 new categories I have an output of 8. How can I make it output 2 rather then 8. Thanks a lot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.