How is this done in php? I've tried several variations of the following:
contact_array[] =
($_POST['contact_relation'],
$_POST['contact_first_name'],
$_POST['contact_last_name'],
$_POST['contact_phone'],
$_POST['contact_email']);
The ultimate goal is to insert the array into a table in a Mysql db.
Thanks,
Bart 6 2225
On Wed, 24 Mar 2004 15:35:38 -0500, Bart Nessux <ba*********@hotmail.com>
wrote: How is this done in php? I've tried several variations of the following:
contact_array[] = ($_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']);
The ultimate goal is to insert the array into a table in a Mysql db. http://uk.php.net/manual/en/function.array.php
$contact_array = array(
$_POST['contact_relation'],
$_POST['contact_first_name'],
$_POST['contact_last_name'],
$_POST['contact_phone'],
$_POST['contact_email']
);
--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Andy Hassall wrote: On Wed, 24 Mar 2004 15:35:38 -0500, Bart Nessux <ba*********@hotmail.com> wrote:
How is this done in php? I've tried several variations of the following:
contact_array[] = ($_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']);
The ultimate goal is to insert the array into a table in a Mysql db. http://uk.php.net/manual/en/function.array.php
$contact_array = array( $_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email'] );
-- Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
That works well. However, I don't understand how to get to the elements
of the inner arrays. I can see all of the arrays, but only the elements
of the last array when I do this:
$contact_array = array(
$_POST['contact_relation'],
$_POST['contact_first_name'],
$_POST['contact_last_name'],
$_POST['contact_phone'],
$_POST['contact_email']);
foreach ($contact_array as $E)
{
echo $E; echo '<br>';
}
foreach ($E as $e)
{
echo $e; echo '<br>';
}
Any more advice?
On Wed, 24 Mar 2004 16:37:38 -0500, Bart Nessux <ba*********@hotmail.com>
wrote: Andy Hassall wrote: On Wed, 24 Mar 2004 15:35:38 -0500, Bart Nessux <ba*********@hotmail.com> wrote:
How is this done in php? I've tried several variations of the following:
contact_array[] = ($_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']);
The ultimate goal is to insert the array into a table in a Mysql db. http://uk.php.net/manual/en/function.array.php
$contact_array = array( $_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email'] );
That works well. However, I don't understand how to get to the elements of the inner arrays. I can see all of the arrays, but only the elements of the last array when I do this:
$contact_array = array( $_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']); foreach ($contact_array as $E) { echo $E; echo '<br>'; } foreach ($E as $e) { echo $e; echo '<br>'; }
Any more advice?
There are no inner arrays, that's a one-dimensional array - what layout were
you expecting? Maybe you need to keep the [] on then as in your original post,
so $contact_array[] = array(...) ?
var_dump($contact_array) may also be useful; put <pre></pre> tags around it to
get the best effect.
--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Bart Nessux wrote: Andy Hassall wrote:
On Wed, 24 Mar 2004 15:35:38 -0500, Bart Nessux <ba*********@hotmail.com> wrote:
How is this done in php? I've tried several variations of the following:
contact_array[] = ($_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']);
The ultimate goal is to insert the array into a table in a Mysql db. http://uk.php.net/manual/en/function.array.php
$contact_array = array( $_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email'] );
-- Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
That works well. However, I don't understand how to get to the elements of the inner arrays. I can see all of the arrays, but only the elements of the last array when I do this:
$contact_array = array( $_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']); foreach ($contact_array as $E) { echo $E; echo '<br>'; } foreach ($E as $e) { echo $e; echo '<br>'; }
Any more advice?
I don't know if it's related but with a clean indentation, you'd see
that the behaviour you complain about is exactly what it should be.
/* loop on each $contact_array */
foreach ($contact_array as $E) {
echo $E; echo '<br>';
}
/* loop on each item of the last item of $contact_array */
foreach ($E as $e) {
echo $e; echo '<br>';
}
If you want to walk through nested arrays, you need to use nested loops:
foreach ($contact_array as $contact) {
echo $contact . "<br>\n";
/* check before, so you won't get an error */
if (is_array($contact)) {
/* and here is the nested loop */
foreach ($contact as $item) {
echo $item . "<br>\n";
}
}
}
Now if $item is an array itself, you'd need 3 nested loops, and so on...
The usual generalisation is to use recursion :
function r_echo($anyarray)
{
echo $anyarray . "<br>\n";
if (is_array($anyarray)) {
foreach($anyarray as $item) {
r_echo($item);
}
}
}
Now there are functions like print_r and var_dump() that already do this...
HTH
Bruno
Bruno Desthuilliers wrote: Bart Nessux wrote:
Andy Hassall wrote:
On Wed, 24 Mar 2004 15:35:38 -0500, Bart Nessux <ba*********@hotmail.com> wrote:
How is this done in php? I've tried several variations of the following:
contact_array[] = ($_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']);
The ultimate goal is to insert the array into a table in a Mysql db.
http://uk.php.net/manual/en/function.array.php
$contact_array = array( $_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email'] );
-- Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space That works well. However, I don't understand how to get to the elements of the inner arrays. I can see all of the arrays, but only the elements of the last array when I do this:
$contact_array = array( $_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']); foreach ($contact_array as $E) { echo $E; echo '<br>'; } foreach ($E as $e) { echo $e; echo '<br>'; }
Any more advice?
I don't know if it's related but with a clean indentation, you'd see that the behaviour you complain about is exactly what it should be.
/* loop on each $contact_array */ foreach ($contact_array as $E) { echo $E; echo '<br>'; }
/* loop on each item of the last item of $contact_array */ foreach ($E as $e) { echo $e; echo '<br>'; }
If you want to walk through nested arrays, you need to use nested loops:
foreach ($contact_array as $contact) { echo $contact . "<br>\n";
/* check before, so you won't get an error */ if (is_array($contact)) { /* and here is the nested loop */ foreach ($contact as $item) { echo $item . "<br>\n"; } } }
Now if $item is an array itself, you'd need 3 nested loops, and so on... The usual generalisation is to use recursion :
function r_echo($anyarray) { echo $anyarray . "<br>\n"; if (is_array($anyarray)) { foreach($anyarray as $item) { r_echo($item); } } }
Now there are functions like print_r and var_dump() that already do this...
HTH Bruno
Thanks guys. Both var_dump() and print_r do what I need. Thanks for the
example function too.
put the second foreach inside the first:
foreach ($contact_array as $E)
{
echo $E; echo '<br>';
foreach ($E as $e)
{
echo $e; echo '<br>';
}
}
On Wed, 24 Mar 2004 16:37:38 -0500, Bart Nessux <ba*********@hotmail.com>
wrote: That works well. However, I don't understand how to get to the elements of the inner arrays. I can see all of the arrays, but only the elements of the last array when I do this:
$contact_array = array( $_POST['contact_relation'], $_POST['contact_first_name'], $_POST['contact_last_name'], $_POST['contact_phone'], $_POST['contact_email']); foreach ($contact_array as $E) { echo $E; echo '<br>'; } foreach ($E as $e) { echo $e; echo '<br>'; }
Any more advice? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gene |
last post by:
I want to create a certain number of arrays on the same time to use,
is it possible to do that?
|
by: yeti349 |
last post by:
Hi, I'm using the following code to retrieve data from an xml file and
populate a javascript array. The data is then displayed in html table
form. I would like to then be able to sort by each...
|
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...
|
by: Richard Lewis Haggard |
last post by:
I am trying to create multi-dimensioned arrays in conventional ASP pages and
pass these arrays as arguments to functions that are in a C# interop
assembly. ASP complains because it doesn't...
|
by: Michael |
last post by:
Hi,
I am trying to pass a function an array of strings, but I am having trouble
getting the indexing to index the strings rather than the individual
characters of one of the strings.
I have...
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these...
|
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...
|
by: =?Utf-8?B?SHVzYW0=?= |
last post by:
Hi EveryBody:
I am using vb.net 2005 and the following code trying to create varible at
runtime:
For n=1 to 4
dim v+n.tostring(n) as double
Next n
the resone behaind using the previous...
|
by: Sunny |
last post by:
Hi,
Is there a way in javascript to create Dynamic arrays or arrays on
fly.
Something Like:
var "ptsgN"+sd = new Array();
Here sd is incrementing by 1.
I have lots of data that I am...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
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)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
| |