473,326 Members | 2,110 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,326 software developers and data experts.

Count NULL fields in a form

Hi, everyone I have a issue I cant seem to figure out. I am trying to count how many fields are not NULL or empty.

the form that I have that post this script has the field name n1,n2,n3 ect...

The reason for this script is to see how many questions are answered.

If anyone can help I would love it so much thanks :)


for ($i=1; $i<count($_POST) ; $i++)
{
$varname = "n$i";
if( ! isset( $_POST[$varname] ) ) break;

$val = $$varname;
// $question_answered = count($_POST);
if(strlen($val) > 0 )
{
$test = array($val, $varname);
echo $val."<br />";
// echo $varname."<br />";

$question_answered = sizeof( $_POST ) != (strlen($val) > 0 );


}
}

echo $question_answered."<br />";
Sep 24 '06 #1
2 2160
ronverdonk
4,258 Expert 4TB
I could not figure out what was wrong, and while toying I made some new code. Throw it away if you don't want this.
[PHP]<?php
$question_answered=0;
$test = array();
for ($i=0, $j=1;$i<count($_POST) ; $i++, $j++) {
if (isset($_POST["n$j"]) AND strlen(trim($_POST["n$j"])) > 0) {
$test["n$j"] = $_POST["n$j"];
$question_answered++;
}
}
echo '<pre> ';
print_r($test);
echo '<br>Questions answered: '.$question_answered."<br />";
?>[/PHP]
Ronald :cool:
Sep 24 '06 #2
OMG thank you so much it works
Sep 24 '06 #3

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

Similar topics

5
by: Aaron C | last post by:
Hi, I'm trying to do an insert with the following statement: INSERT INTO user VALUES ( 'ag@ag.com','ag','Aaron','Chandler','','','La Mirada','CA',90638,714,'',''); and I'm getting the error...
2
by: Steve Bishop | last post by:
I am trying to do a summary SQL query. I have 3 fields. If one filed is null and the other is not null, I want to count how many records there are. I also want to count the opposite way then count...
3
by: Zb Bornemann | last post by:
Hi All, Ok. Here's what my table looks like: Field1 Field2 Field3 Field4... Record1 1 3 2 9 Record2 9 1 9 ...
1
by: griemer | last post by:
I have a database like this id, field1,field2,field3,field4,field5 Database contains 100 rows, some rows have no fields filled, some 1field , some 2 fields etc. How would i count the...
1
by: sunilkeswani | last post by:
Hi I am still new to access. I want to know how i can build a query which can display results from 4 different columns/fields Like. Field1 Field2 Field3 Field4 1 2 1 ...
3
by: cdownload | last post by:
I have 7 fields to key to on a form. Is there a way to count the number fields that have for example, a value greater than zero?
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...
1
by: iht | last post by:
Fairly new to Access and really doesn't know much about SQL except some basic commands. Currently I'm working with a database that I've already sorted by some queries, and here's a simplified...
1
by: dud10 | last post by:
Hi All, I´m having a problem with count of null values fields and indexes... I have a table (tb_Propose) with around 8 million lines. A field Dt_flag -- Datetime An index Ix_Dt_flag,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.