Page 1 of 1
$_REQUEST['whatever'] questions
Posted: Tue Feb 10, 2004 11:26 am
by Saethyr
Okay I have a list of POST variables that I need to concatenate into one variable for entry into a table cell in a database, the list of variables is C1 Through C55. What would be the best way to concat these variables into one single variable for entry into a database?
Posted: Tue Feb 10, 2004 11:57 am
by qads
somthing like this might help..
Code: Select all
<?php
foreach($_POST as $key => $value)
{
$var .= $value.', ';
}
echo$var;
?>
Posted: Tue Feb 10, 2004 12:10 pm
by Saethyr
qads,
I thought about that as well but, there are several Post variables I do not want to concat. A1-A15, B1-B20, C1-C32, D1-D10 each will be concat'd in it's own variable, sorry I know I didn't add that piece of information in the original post. would it be easier just to name the variables like C[] and create an array out of each one?
Posted: Tue Feb 10, 2004 2:57 pm
by DuFF
Using C[] as the form field name would probably be the best way. If not, maybe this would work?
Code: Select all
<?
foreach($_POST as $key => $value)
{
$pos = strpos($value, "C")
if($pos === true) // Note use of ===. Simply == would not work as expected
{
$C[] .= $value.', ';
}
}
echo$var;
?>
Posted: Tue Feb 10, 2004 2:59 pm
by Saethyr
Duff,
Thanks bro, I will work with that and see what I can get going.
Posted: Wed Feb 11, 2004 4:07 am
by twigletmac
An alternate method would be using a for loop:
Code: Select all
$concat_string = '';
for ($i = 1; $i <= 55; $i++) {
$concat_string .= $_POST['C'.$i];
}
Mac