472,954 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Array filtering

41
Hi

Seasons Greetings

Its back, I am being haunted.

I thought I had resolved this problem but I am intermittently
the receving the warnings below.

This code consist of a 1) HTML form, 2) a display function on the HTML form and
3) a process to manage the form input.

Can you show me what I am doing wrong and or how to correct it ?

Message received:

Warning: array_filter() [function.array-filter]:
The first argument should be an array in D:\search_process.php on line 155

Warning: array_filter() [function.array-filter]:
The first argument should be an array in D:\search_process.php on line 156

Warning: array_filter() [function.array-filter]:
The first argument should be an array in D:\search_process.php on line 171

Warning: array_filter() [function.array-filter]:
The first argument should be an array in D:\search_process.php on line 172


Note: I have proveded only a small portion of the related code.




[html]
<!--/**FORM**/-->
{//function start

//for loop start
{


echo"<tr height=\"10\">
<td width=\"4%\" bgcolor=\"#fff8dc\" align=\"center\">
<input type=\"checkbox\" name=\"fee1_choice[$i]\" value=\"$code_id\"></td>
<td width=\"7%\" bgcolor=\"#fff8dc\" ><span class=\"style20\"><strong>$fee1_code</strong></span></td>
<td width=\"3%\" bgcolor=\"$bgcolor\" height=\"10\">
<input type=\"text\" name=\"fee1_unit[$i]\" size=\"1\" maxlength=\"2\" value =\"$fee1_unit\"/>
</td>
<td width=\"79%\" bgcolor=\"$bgcolor\" class=\"style20\"> $description </td>
<td width=\"6%\" align=\"left\">$s_fee</td>\n";
echo"</tr>\n";

}//end of loop

//assign all arrays into single array for the return statement
$all_array = array(fee_choice, fee_unit, fee_money, fee1_choice, fee1_unit, fee1_fee, fee2_choice, fee2_code, fee2_unit, fee2_describe, fee2_money, fee3_choice, fee3_code, fee3_unit, fee3_describe, fee3_money);

//return array from function
return ($all_array);

}//end of function

//unpack returned array
list($fee_choice, $fee_unit, $fee_money, $fee1_choice, $fee1_unit, $fee1_fee, $fee2_choice, $fee2_code, $fee2_unit, $fee2_describe, $fee2_money, $fee3_choice, $fee3_code, $fee3_unit, $fee3_describe, $fee3_money )= $all_array;

[/html]


[/php]


I changed the format of the array returned by the function
and thoug thr problem was solved but I startr to get the errors again

[php]
<?
$all_array = array($fee_choice, $fee_unit, $fee_money, $fee1_choice,
$fee1_unit, $fee1_fee, $fee2_choice, $fee2_code, $fee2_unit, $fee2_describe,
$fee2_money, $fee3_choice, $fee3_code, $fee3_unit, $fee3_describe, $fee3_money);
?>
[/php]


[php]

<?php
/**PROCESS**/

/**data from form**/
$fee_unit = $_POST['fee_unit'];//array with the number of units
$fee_money = $_POST['fee_money'];//array selected fee

//filter blank indexes
$fee_unit = array_filter($fee_unit); //line 155
$fee_money = array_filter($fee_money); //line 156


/**data from form**/
$fee1_unit = $_POST['fee1_unit'];//array with the number of units
$fee1_money = $_POST['fee1_money'];//array selected fee


//filter blank indexes
$fee1_unit = array_filter($fee1_unit); //line 171
$fee1_money = array_filter($fee1_money);//line 172

/** get array contents for insertion**/
$indices2 = array_keys($code1_id);
foreach($indices2 as $index2)
{
//individual value validation from 3 arrays
$code1_id[$index2];
$fee1_unit[$index2];
$fee1_money[$index2];

//validate unit
$field_unit = $fee1_unit[$index2];//assign field to array for function
check_unit_field($field_unit);//funtion to validate user entered numbers or message sent


//insert statement goes here

}
?>
[/php]

I have added the code below to the process to get rid of
the errors but this creates another problem where the
foreach loop can't extract the data from the arrays.


[php]
<?
//create array A
$fee_unit = array($fee_unit);
$fee_money = array($fee_money);


//create array B
$fee1_unit = array($fee1_unit);
$fee1_money = array($fee1_money);
?>

[/php]
Dec 20 '06 #1
4 1929
ronverdonk
4,258 Expert 4TB
You forgot to post an important part of your code i.e. the form that is submitted with the array in it. Please show us.

Ronald :cool:
Dec 20 '06 #2
assgar
41
I am very sorry but I accidentally deleted your reply. But I have seen it and, maybe I am missing some important part, but I cannot see anywhere on your to-be-submitted form the 2 fields that you extract from the POST array, i.e.[php]$fee_unit = $_POST['fee_unit'];//array with the number of units
$fee_money = $_POST['fee_money'];//array selected fee
[/php]

Ronald :cool:
Jan 3 '07 #3
assgar
41
I am very sorry but I accidentally deleted your reply. But I have seen it and, maybe I am missing some important part, but I cannot see anywhere on your to-be-submitted form the 2 fields that you extract from the POST array, i.e.[php]$fee_unit = $_POST['fee_unit'];//array with the number of units
$fee_money = $_POST['fee_money'];//array selected fee
[/php]

Ronald :cool:

Hi Ron

Thanks for replaying.

I think this is what you are looking for. The names were messed up in my
example. I appologize for the length.


This is the function that display the information on the form.
[php]
<?php

function display($services, $special, $fee_master_table)
{

if ($services == "A")
{
$data = "SELECT c.code_id, c.fee_code, c.description, m.general_fee,
m.technical_fee, m.specialist_fee, m.anaesthetist_fee,
m.non_anaesthetist_fee
FROM bill_ohip_fee_code c, $fee_master_table m
WHERE c.fee_code = m.code
AND c.specialty = '$special'
ORDER BY c.fee_code
";
}


$result = mysqli_query($mysqli,$data);
$num_service = mysqli_num_rows($result);
for($i=0; $i < $num_service; $i++)
{
$row = mysqli_fetch_array($result);

list($code_id, $fee1_code, $description, $general_fee, $technical_fee,
$specialist_fee, $anaesthetist_fee, $non_anaesthetist_fee) = $row;


//dropdown list of fees that filter out 0.00
$s_fee = "<select name=\"fee_money[$i]\" >";
$s_fee .= "<option value=\"\" selected> Select</option>";
if($general > 0.00)
$s_fee .= "<option value = \"$general\">Gen: $general</option>";
if($technical > 0.00)
$s_fee .= "<option value = \"$technical\">Tec: $technical</option>";
if($specialist > 0.00)
$s_fee .= "<option value = \"$specialist\">Spe: $specialist</option>";
if($anaesthetist > 0.00)
$s_fee .= "<option value = \"$anaesthetist\">Ana: $anaesthetist</option>";
if($non_anaesthetist > 0.00)
$s_fee .= "<option value = \"$non_anaesthetist\">Non: $non_anaesthetist</option>";
//input box is displayed if no fee values for all 5
elseif($general == 0.00 && $technical == 0.00 && $specialist == 0.00 &&
$anaesthetist == 0.00 && $non_anaesthetist == 0.00)
$s_fee = "<input type=\"text\" name=\"fee[money]\" size=\"9\" maxlength=\"7\" value =\"$ohip_fee\"/>\n";
$s_fee .= "</select>";


if($i % 2) //alternate row colour
{
$bgcolor="#eeeee0";
}
else
{
$bgcolor="#ebeae0";
}

//diaplay search results in rows
echo"<tr height=\"10\">
<td width=\"4%\" bgcolor=\"#fff8dc\" align=\"center\">
<input type=\"radio\" name=\"choice[]\" value=\"$code_id\" selected>
<input type=\"hidden\" name=\"fee1_choice[$i]\" value=\"$code_id\"></td>
<td width=\"7%\" bgcolor=\"#fff8dc\"><span class=\"style20\">
<div style = \"margin:5;\"><strong>$fee1_code</strong></span></div></td>
<td width=\"3%\" bgcolor=\"$bgcolor\" height=\"10\">
<input type=\"text\" name=\"fee_unit[$i]\" size=\"1\" maxlength=\"2\" value =\"$fee1_unit\"/></td>
<td width=\"79%\" bgcolor=\"$bgcolor\" class=\"style20\">
<div style = \"margin:5;\">$description </div></td>
<td width=\"6%\" align=\"left\">$s_fee</td>\n";
echo"</tr>\n";

}//end of for loop



echo"</div>\n";
echo "</div>\n";
echo "</table>\n";

$mysqli->close();//close connection to db

//assign all arrays into single array for the return statement
$all_array = array(choice, fee_choice, fee_unit, fee_money, fee1_choice,
fee1_unit, fee1_fee, fee2_choice, fee2_unit, fee2_describe,
fee2_money, fee3_code, fee3_unit, fee3_describe, fee3_money);

//return array from function
return ($all_array);

}//end of function

//unpack returned array
list($choice, $fee_choice, $fee_unit, $fee_money, $fee1_choice,
$fee1_unit, $fee1_fee, $fee2_code, $fee2_unit, $fee2_describe,
$fee2_money, $fee3_code, $fee3_unit, $fee3_describe, $fee3_money )= $all_array;
?>
[/php]
Jan 5 '07 #4
assgar
41
Hi Ron

Thanks for replaying.

I think this is what you are looking for. The names were messed up in my
example. I appologize for the length.


This is the function that display the information on the form.
[php]
<?php

function display($services, $special, $fee_master_table)
{

if ($services == "A")
{
$data = "SELECT c.code_id, c.fee_code, c.description, m.general_fee,
m.technical_fee, m.specialist_fee, m.anaesthetist_fee,
m.non_anaesthetist_fee
FROM bill_ohip_fee_code c, $fee_master_table m
WHERE c.fee_code = m.code
AND c.specialty = '$special'
ORDER BY c.fee_code
";
}


$result = mysqli_query($mysqli,$data);
$num_service = mysqli_num_rows($result);
for($i=0; $i < $num_service; $i++)
{
$row = mysqli_fetch_array($result);

list($code_id, $fee1_code, $description, $general_fee, $technical_fee,
$specialist_fee, $anaesthetist_fee, $non_anaesthetist_fee) = $row;


//dropdown list of fees that filter out 0.00
$s_fee = "<select name=\"fee_money[$i]\" >";
$s_fee .= "<option value=\"\" selected> Select</option>";
if($general > 0.00)
$s_fee .= "<option value = \"$general\">Gen: $general</option>";
if($technical > 0.00)
$s_fee .= "<option value = \"$technical\">Tec: $technical</option>";
if($specialist > 0.00)
$s_fee .= "<option value = \"$specialist\">Spe: $specialist</option>";
if($anaesthetist > 0.00)
$s_fee .= "<option value = \"$anaesthetist\">Ana: $anaesthetist</option>";
if($non_anaesthetist > 0.00)
$s_fee .= "<option value = \"$non_anaesthetist\">Non: $non_anaesthetist</option>";
//input box is displayed if no fee values for all 5
elseif($general == 0.00 && $technical == 0.00 && $specialist == 0.00 &&
$anaesthetist == 0.00 && $non_anaesthetist == 0.00)
$s_fee = "<input type=\"text\" name=\"fee[money]\" size=\"9\" maxlength=\"7\" value =\"$ohip_fee\"/>\n";
$s_fee .= "</select>";


if($i % 2) //alternate row colour
{
$bgcolor="#eeeee0";
}
else
{
$bgcolor="#ebeae0";
}

//diaplay search results in rows
echo"<tr height=\"10\">
<td width=\"4%\" bgcolor=\"#fff8dc\" align=\"center\">
<input type=\"radio\" name=\"choice[]\" value=\"$code_id\" selected>
<input type=\"hidden\" name=\"fee1_choice[$i]\" value=\"$code_id\"></td>
<td width=\"7%\" bgcolor=\"#fff8dc\"><span class=\"style20\">
<div style = \"margin:5;\"><strong>$fee1_code</strong></span></div></td>
<td width=\"3%\" bgcolor=\"$bgcolor\" height=\"10\">
<input type=\"text\" name=\"fee_unit[$i]\" size=\"1\" maxlength=\"2\" value =\"$fee1_unit\"/></td>
<td width=\"79%\" bgcolor=\"$bgcolor\" class=\"style20\">
<div style = \"margin:5;\">$description </div></td>
<td width=\"6%\" align=\"left\">$s_fee</td>\n";
echo"</tr>\n";

}//end of for loop



echo"</div>\n";
echo "</div>\n";
echo "</table>\n";

$mysqli->close();//close connection to db

//assign all arrays into single array for the return statement
$all_array = array(choice, fee_choice, fee_unit, fee_money, fee1_choice,
fee1_unit, fee1_fee, fee2_choice, fee2_unit, fee2_describe,
fee2_money, fee3_code, fee3_unit, fee3_describe, fee3_money);

//return array from function
return ($all_array);

}//end of function

//unpack returned array
list($choice, $fee_choice, $fee_unit, $fee_money, $fee1_choice,
$fee1_unit, $fee1_fee, $fee2_code, $fee2_unit, $fee2_describe,
$fee2_money, $fee3_code, $fee3_unit, $fee3_describe, $fee3_money )= $all_array;
?>
[/php]

Hi

I have been using this bit of code to resolve the problem for over
a week and have not received the error message.

This can be considered resolved.


[php]

/*** arrays passed from the form with selected service variables ***/
$code_id = $_POST['fee_choice']; //array of code_id primary key
$fee_unit = $_POST['fee_unit'];//array with the number of units
$fee_money = $_POST['fee_money'];//array selected fee


//filter array $fee_unit
if(is_array($fee_unit))
{
$fee_unit = array_filter($fee_unit);
}
else
{
$fee_unit = array($fee_unit);
$fee_unit = array_filter($fee_unit);
}
//filter array $fee_money
if(is_array($fee_money))
{
$fee_money = array_filter($fee_money);
}
else
{
$fee_money = array($fee_money);
$fee_money = array_filter($fee_money);
}

[/php]
Jan 15 '07 #5

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

Similar topics

1
by: Geoff Soper | last post by:
I would like to be able to filter every element of a multi-dimensional array using htmlspecialchars() and to retain the structure of the array. I can't see how to do this when I don't know how many...
8
by: Tim Pollard | last post by:
Hi I am trying to filter a table of users to select only those records whose roleID matches a value in an array. There could be any number of IDs held in the array from one to a few hundred. The...
1
by: iCeCLoW | last post by:
Hi there, I´m using the rowFilter property for filtering the rows in a DataView object. If the filter is set to an inexistent value , that is, after filtering i have 0 rows in the DataView,...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
6
by: Les Juby | last post by:
I need to extract records from a database subject to conditions and only thereafter give the users the choice of which fields to sort the results on. In this situation I can't write back to a...
2
by: JUAN ERNESTO FLORES BELTRAN | last post by:
Hi you all, I am developping a python application which connects to a database (postresql) and displays the query results on a treeview. In adittion to displaying the info i do need to implement...
11
by: Cliff Martin | last post by:
Hi, I am reading a fairly large file a line at a time, doing some processing, and filtering out bits of the line. I am storing the interesting information in a struct and then printing it out....
2
by: Compass | last post by:
Hi all, I have an int array in a text file. The file structure is like this: , , , ] How can I easily read them in to three int arrays? Thanks a lot!
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.