Hi Ron
Your point about the posting guide lines is a good one.
Development platform: Windows 2003 server with apache, Mysql and PHP.
Website: Linux server with apache, Mysql and PHP.
No errors.
The form I am working on lists information by category from a Mysql database.
The user can also search for information by code or description.
Note: The table being searched has over 5000 unique rows. The dynamic listing might display a list of 100 to 400 rows so the user can select multiple rows.
My form is 519 lines and the none dynamic protion has individual field names. The lower portion of this form displays two sets dynamically created
displays. The dynamically created display areas are created by function display() which is 400 lines. I might have over simplified.
Form
<?php
include("displa y.php); //function to display dynamic area
?>
<html>
<head>
</head>
<body>
<form action = "search_process .php" method = "post">
<div id ="layer 1" style="psoition :absolute; left:0px; top:0; width:99%; height:800px; z--index:1;">
<table width="100%" height="100px" border="0">
<tr width="100%">
<td colspan"5" align="right">
<input type="submit" name="the_butto n" value="Cancel">
<input type="submit" name="the_butto n" value="Submit">
</td>
</tr>
</table>
</div>
<?php
echo display();//display dynamic rows
?>
</form>
</body>
</html>
Function
<?php
display() //function name
{
/**portion of the function's form collecting information**/
$data = "select cide_id, fee_code, description, fee
from code_table
where des__code = '$services'
$result = mysqli_qurey($m ysqli, $data);
while($row = mysqli_fetch_ar ray($result))
{
$code_id = $row['code_id'];
$fee_code = $row['fee_code'];
$description = $row['description'];
$fee = $row['fee'];
echo "<table>";
echo"<tr height=\"10\">
<td width=\"2%\" bgcolor=\"#fff8 dc\" align=\"center\ ">
<input type=\"checkbox \" size=\"2%\" name=\"fee_choi ce[]\"
value=\"$fee_ch oice2\"></td>
<td width=\"3%\" bgcolor=\"#fff8 dc\">
<input type=\"text\" name=\"fee_code[]\"
size=\"3%\" maxlength=\"2\" value =\"$fee_code\ "/></td>
<td width=\"3%\" bgcolor=\"#eeee e0\" height=\"10\">
<input type=\"text\" name=\"fee_unit[]\"
size=\"1%\" maxlength=\"2\" value =\"$fee_unit\ "/></td>
<td width=\"80%\" bgcolor=\"#eeee e0\">
<input type=\"text\" name=\"fee_desc ribe[]\"
size=\"100%\" maxlength=\"2\" value =\"$fee_describ e\"/></td>
<td width=\"12%\" align=\"left\">
<input type=\"text\" name=\"fee_fee[]\"
size=\"12%\" maxlength=\"2\" value =\"$fee_fee\"/></td>\n";
echo"</tr>\n";
echo"</table>\n";
/**the function returning collected information **/
return $all_array = array('fee_choi ce[]', 'fee_code[]', 'fee_unit[]',
'fee_describe[]', 'fee_fee[]');
}
?>
Process
29,928 Community Members Welcome, assgar. | 0 PMs | Control Panel | Buddy List | Log Out
Home Discussions Tutorials Members FAQ
Community > Web Development > PHP
Using array to pass data
assgar
Junior Member
6 Posts Today
03:01 AM
#1
Using array to pass data
--------------------------------------------------------------------------------
I might not be appoaching this correctly because it is not working.
I have a function that displays a dynamic form for the user to make one or more selections.
There are 5 arrays to collect the 5 pieces of information relelated to each dynamically created rows.
I am trying to return the collected information in the 5 arrays to the process so I can use it to insert into a database.
PHP Code:
Hi Ron
I messed up on the submit and the edit time ran out
so I have added some of the missing info.
Your suggestion sounds good, I would like to keep the form, most of the function, the process can change.
Function
<?php
display() //function name
{
/**portion of the function's form collecting information**/
$data = "select cide_id, fee_code, description, fee
from code_table
where des__code = '$services'
$result = mysqli_qurey($m ysqli, $data);
while($row = mysqli_fetch_ar ray($result))
{
$code_id = $row['code_id'];
$fee_code = $row['fee_code'];
$description = $row['description'];
$fee = $row['fee'];
echo "<table>";
echo"<tr height=\"10\">
<td width=\"2%\" bgcolor=\"#fff8 dc\" align=\"center\ ">
<input type=\"checkbox \" size=\"2%\" name=\"fee_choi ce[]\"
value=\"$fee_ch oice2\"></td>
<td width=\"3%\" bgcolor=\"#fff8 dc\">
<input type=\"text\" name=\"fee_code[]\"
size=\"3%\" maxlength=\"2\" value =\"$fee_code\ "/></td>
<td width=\"3%\" bgcolor=\"#eeee e0\" height=\"10\">
<input type=\"text\" name=\"fee_unit[]\"
size=\"1%\" maxlength=\"2\" value =\"$fee_unit\ "/></td>
<td width=\"80%\" bgcolor=\"#eeee e0\">
<input type=\"text\" name=\"fee_desc ribe[]\"
size=\"100%\" maxlength=\"2\" value =\"$fee_describ e\"/></td>
<td width=\"12%\" align=\"left\">
<input type=\"text\" name=\"fee_fee[]\"
size=\"12%\" maxlength=\"2\" value =\"$fee_fee\"/></td>\n";
echo"</tr>\n";
echo"</table>\n";
/**the function returning collected information **/
return $all_array = array('fee_choi ce[]', 'fee_code[]', 'fee_unit[]',
'fee_describe[]', 'fee_fee[]');
}
}
Process: display.php
<?php
/******PROCESS** *****/
/**getting the 5 inital arrays out of the $all_array so I can use a loop to insert**/
$all_array = strip_tags(trim ($_POST[$all_array]));
$all_array = ereg_replace("[)(-]","",$all_array );
$all_array = explode(",", $all_array);
$fee_choice = $all_array[0];
$fee_code = $all_array[1];
$fee_unit = $all_array[2];
$fee_describe = $all_array[3];
$fee_fee = $all_array[4];
/**loop to insert **/
for($i=0; $i < count($fee_choi ce); $i++)
{
$dynamic_in = "INSERT INTO table_a(
id, fee_code, fee_describe, fee_fee,
fee_unit, coverage, total)
VALUES (
null, '$fee_code', '$fee_describe' , '$fee_fee',
'$fee_unit', '$coverage', '$total')";
//open connection
mysqli_query($m ysqli, $dynamic_in)or die(mysqli_erro r($mysqli));
}
?>