473,769 Members | 5,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using array to pass data

41 New Member
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]
<?php
/****FORM*****/
display() //function name
{

/**portion of the function's form collecting information**/
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_code2 \"/></td>
<td width=\"3%\" bgcolor=\"#eeee e0\" height=\"10\">
<input type=\"text\" name=\"fee_unit[]\"
size=\"1%\" maxlength=\"2\" value =\"$fee_unit2 \"/></td>
<td width=\"80%\" bgcolor=\"#eeee e0\">
<input type=\"text\" name=\"fee_desc ribe[]\"
size=\"100%\" maxlength=\"2\" value =\"$fee_describ e2\"/></td>
<td width=\"12%\" align=\"left\">
<input type=\"text\" name=\"fee_fee[]\"
size=\"12%\" maxlength=\"2\" value =\"$fee_fee2\ "/></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[]');

}
?>

<?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));
}
?>
[/php]
Oct 11 '06 #1
3 2494
ronverdonk
4,258 Recognized Expert Specialist
First: read the Posting Guidelines at the top of this form and post any code within the [php] or [code] tags!! That makes it a lot easier to read and to comment on.

On to your question: you use a lot of arrays here and their purpose it not clear since you only use 1 value of each array.

Also I don't see any <form> around the table in which the fields must be entered, so I wonder how you want to extract the values without either submitting a form or using dynamic JS.

I think you need to re-arrange your script in the following way:
  • let the values be entered in in a <form> construction in 'normal' fields and pass the values of that form to your script via a POST;
  • read the POSTed variables (after submit), assign them to local variables and perform your database operations.
If you agree, let me know and we can see how to do that.
If I have misunderstood the purpose of your script, let me know and we'll go from there.

Ronald :cool:
Oct 11 '06 #2
assgar
41 New Member
First: read the Posting Guidelines at the top of this form and post any code within the [php] or [code] tags!! That makes it a lot easier to read and to comment on.

On to your question: you use a lot of arrays here and their purpose it not clear since you only use 1 value of each array.

Also I don't see any <form> around the table in which the fields must be entered, so I wonder how you want to extract the values without either submitting a form or using dynamic JS.

I think you need to re-arrange your script in the following way:
  • let the values be entered in in a <form> construction in 'normal' fields and pass the values of that form to your script via a POST;
  • read the POSTed variables (after submit), assign them to local variables and perform your database operations.
If you agree, let me know and we can see how to do that.
If I have misunderstood the purpose of your script, let me know and we'll go from there.

Ronald :cool:

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))



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_code2 \"/></td>
<td width=\"3%\" bgcolor=\"#eeee e0\" height=\"10\">
<input type=\"text\" name=\"fee_unit[]\"
size=\"1%\" maxlength=\"2\" value =\"$fee_unit2 \"/></td>
<td width=\"80%\" bgcolor=\"#eeee e0\">
<input type=\"text\" name=\"fee_desc ribe[]\"
size=\"100%\" maxlength=\"2\" value =\"$fee_describ e2\"/></td>
<td width=\"12%\" align=\"left\">
<input type=\"text\" name=\"fee_fee[]\"
size=\"12%\" maxlength=\"2\" value =\"$fee_fee2\ "/></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[]');

}
?>
Oct 11 '06 #3
assgar
41 New Member
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));
}
?>
Oct 11 '06 #4

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

Similar topics

5
11201
by: David Rasmussen | last post by:
Some sites seem to be session driven in the sense that if I visit the homepage and do a few clicks I can navigate anywhere I want, but if I paste the current location into a new browser window after having navigated to some page, it doesn't work. It just returns to the start page or says "timeout" etc. This means that I can't read these pages from PHP with $string = file_get_contents('http://some.url/blah/deep/link');
1
2257
by: Brian McGuinness | last post by:
I have a question about using the STL transform algorithm in a function. What I want to do is define a group of array classes to represent APL-style arrays (arrays in which the number of dimensions and the length of any dimension can be changed at any time). What I currently plan is to have an abstract base class at the top, to allow polymorphism, e.g.: #include "basedefs.h" // Basic data types, e.g. typedef long Integer
15
14879
by: John Alway | last post by:
Hello, I'm using a DLL I wrote in C++, and am attempting to call and use it from VB. This works fine for functions where I pass parameters by value, but I can't get pointers to work. I get the following error in the VB.net application: "An unhandled exception of Type
3
2833
by: questions? | last post by:
I tried to pass a two dimensional array in the function arguments the following program is a demonstration, ******************************************** # include <stdio.h> # include <string.h> double data={{1.0, 3.0},{9.0, 8.0}};
14
3132
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are very unhappy with the idea and the compiler refuses to play ball with any of the attempts I have made to build such a structure. There is no problem when using a single string but a two dimensional array of strings appears to be a very different...
5
2018
by: frothpoker | last post by:
Guys, I have a couple of issues which I am hoping you can provide guidance on... First one:- Is there any way to retain the $_POST values when a user navigates between pages without using <form method = 'post'> I want to be able to track the user from one page to another to provide customised content. I could make all navigation buttons as forms but
14
20411
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is passed also. I understand that this way of passing the array is by value and if the prototype is declared as foo(int *), it is by reference in which case the value if modified in the function will get reflected in the main function as well. I dont...
7
8134
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h> #include<stdlib.h> #include<math.h>
17
7254
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
65
3927
by: Arjen | last post by:
Hi, Form a performance perspective, is it wise to use the ref statement as much as possible? Thanks! Arjen
0
9423
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
10222
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
10050
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
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5310
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
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
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.