This topic is locked

How to count the number of fields with value in a row

8/15/2008 3:22:36 PM
PHPRunner General questions
F
fid author

Hello forum.
i have six mediumtext fields where the user can upload files.

i want to see the total nº of files that every record have.
field1, field2, field3, field4, field5, field6, total.
if user upload one file the total field must be 1.
I am trying to do count ($_FILES) but i don't know how to do it.

T
thesofa 8/15/2008

you could try something along these lines

$number_of_files="0";

if($values["field1"]!="")

{

$number_of_files++

}

if($values["field2"]!="")

{

$number_of_files++

}

if($values["field3"]!="")

{

$number_of_files++

}

if($values["field4"]!="")

{

$number_of_files++

}

if($values["field5"]!="")

{

$number_of_files++

}

if($values["field1"]!="")

{

$number_of_files++

}

$values["total"]=$number_of_files;

return true;
F
fid author 8/16/2008

Thanks!!

i only have to put ";" after $number_of_files++;
$number_of_files="0";

if($values["Folha_1"]!="")

{

$number_of_files++;

}

if($values["Folha_2"]!="")

{

$number_of_files++;

}

if($values["Folha_3"]!="")

{

$number_of_files++;

}

if($values["Folha_4"]!="")

{

$number_of_files++;

}

if($values["Folha_5"]!="")

{

$number_of_files++;

}

if($values["Folha_6"]!="")

{

$number_of_files++;

}

$values["Total"]=$number_of_files;
return true;

F
fid author 8/16/2008

Now i need deal with the Before edit... $oldvalues

When i edit a page i have the option to maintain, remove and change uploaded files and the total field return 0 if i not make any changes.