473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Counting field and update database

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.

I have tried to use:

$checked = count($_POST['category']);

but with this one, if I already have 2 selected then choose another two then the database will update 4 cats rather then the new added 2.

thanks in advance
Nov 13 '07 #1
1 1353
you can get a list/count of selected checkboxes like this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $categories = $_POST['categories'];
  4.  
  5. if (isset($categories))
  6. {
  7.     foreach ($categories as $value)
  8.     {
  9.         echo "$value<br>";
  10.     }
  11.  
  12.     echo "<Br><BR>Items:";
  13.     echo sizeof($categories);
  14. }
  15. else
  16. {
  17.     echo ("<form method=post>
  18.     <input type='checkbox' name='categories[]' value='Comedy'>Comedy<BR>
  19.     <input type='checkbox' name='categories[]' value='Horror'>Horror<BR>
  20.     <input type='checkbox' name='categories[]' value='Action'>Action<BR>
  21.     <input type='checkbox' name='categories[]' value='Musical'>Musical<BR>
  22.     <input type='Submit' value='Select'>");
  23. }
  24.  
  25. ?>
  26.  
Nov 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tim | last post by:
I don't know what to use to clear a field in an MSAccess database. I can update fields in the database and delete whole records but I have not figured out how to clear a single field. This is...
3
by: BlackFireNova | last post by:
This concerns an Access 2002 (XP) database. There are two fields, "Notes" (Memo Field) and "Notes Update" on a form (among others) which I am concerned with here. Problem: I need to be able...
3
by: Megan | last post by:
hi everybody- i'm having a counting problem i hope you guys and gals could give me some help with. i have a query that retrieves a bevy of information from several different tables. first let...
3
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is...
11
by: pmarisole | last post by:
I am trying to use the vbscript "split" function on a multi-select field. I am trying to do a mass update of several records at a time. I am getting an error and I'm not sure what to do. Here is...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
2
by: DaFerg | last post by:
Hi ... I have a weblog database where I want to count the occurences of a table of string values that appear in all the urls viewed. My tblWebLog as a field that contains the url ... tblWebLog....
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
3
by: pezz | last post by:
Helly my Experts, i am working with access 2000 on windows 2000. I have a database with many tables. I would like to count the entries in one of this tables and show the totals in a field in the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.