RE: Question: Putting separate form elements into an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not exactly sure what I did here.  
there are 5 skill textfields name skill[]
then the years sky[]
then the last used slu[]

I was following the format of my other arrays, so
stored them list this:

if ( empty( $_SESSION['l_skill'] ) ) {
$_SESSION['l_skill']=array();
}

if ( is_array( $_REQUEST['skill'] ) ) {
$_SESSION['l_skill'] = array_unique(
array_merge( $_SESSION['l_skill'],
 $_REQUEST['skill'] )
);
}
if ( empty( $_SESSION['l_years'] ) ) {
$_SESSION['l_years']=array();
}

if ( is_array( $_REQUEST['sky'] ) ) {
$_SESSION['l_years'] = array_unique(
array_merge( $_SESSION['l_years'],
 $_REQUEST['sky'] )
);
}
if ( empty( $_SESSION['l_lastu'] ) ) {
$_SESSION['l_lastu']=array();
}

if ( is_array( $_REQUEST['slu'] ) ) {
$_SESSION['l_lastu'] = array_unique(
array_merge( $_SESSION['l_lastu'],
 $_REQUEST['slu'] )
);
}

I think that is all fine, but I think at the critical
moment (setup for database transaction is where my
problem is and it's probably slight)Read past the code
for my explanation.


if ( is_array( $_SESSION['l_skill'] ) ) {
	foreach ( $_SESSION['l_skill'] as $s ) {
	}
}
		if ( is_array( $_SESSION['l_years'] ) ) {
			foreach ( $_SESSION['l_years'] as $x ) {
	}
}
					if ( is_array( $_SESSION['l_lastu'] ) ) {
							foreach ( $_SESSION['l_lastu'] as $z ) {
	}
}

$query = "INSERT INTO .............)
VALUES ($...., '$s', $x, $z)";

At first I thought to nest all the "if ( is_array"
but that produced some funky loop.
So then I formatted as aboved.  Problem is all i'm
getting is the last element from each array into the
database.  
I'm thinking then, perhaps not nested , but the if is
arrays need to be formatted differently.

Stuart




--- Graham Cossey <graham@xxxxxxxxxxxxxxx> wrote:

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux