473,800 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting field and update database

1 New Member
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 1377
assimlation
9 New Member
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
2144
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 what I am using to update the database. Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open "DSN=DataBase" SQL = "UPDATE Table SET " SQL = SQL & "thefield='" & Request.Form("thefield1") & "', "
3
12973
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 to tell when people have added notes to a record. (this database contains 6000+ records) I want to set it up so that "Notes Update" is updated to the current date whenever someone actually enters data into, or modifies data in, the "Notes"...
3
1969
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 me give you a little background. this database is kind of like a human resources database. it collects info about people, where they work, and if they have any work-related issues where they work.
3
1879
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 not there, of course. How do I get that field back into the datatable for the database update? TIA, Larry Woods
11
4442
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 the code if someone could help... strID = split(request.form("proj"), ", ") projstat = split(request.form("rojstat"),",") impr = split(request.form("impr"),",") idate =...
2
19615
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 field in table2. What I have is a form that is linked to Table2. If the users want to change a field in the main database (table1), they fill the change in to the form (which is linked to table2) If there is no change to the field, they simply...
2
1980
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. I have another table ... tblStrings ... that has a field for a string value and an integer field to count the occurence of the string in tblWebLog.
5
4104
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 table in design mode and then add the new field and set its properties. Thanks. --
3
1524
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 main tables. I try to be more practical: i am an epidemiologist and i have different labs (main table) each with different patients (second table). In the first table i would like access to create a new field and in thius field show me how many...
0
9695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9555
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10514
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10287
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7588
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6826
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.