$_REQUEST['whatever'] questions
Moderator: General Moderators
- Saethyr
- Forum Contributor
- Posts: 182
- Joined: Thu Sep 25, 2003 9:21 am
- Location: Wichita, Kansas USA
- Contact:
$_REQUEST['whatever'] questions
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?
somthing like this might help..
Code: Select all
<?php
foreach($_POST as $key => $value)
{
$var .= $value.', ';
}
echo$var;
?>- Saethyr
- Forum Contributor
- Posts: 182
- Joined: Thu Sep 25, 2003 9:21 am
- Location: Wichita, Kansas USA
- Contact:
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?
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?
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;
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
An alternate method would be using a for loop:
Mac
Code: Select all
$concat_string = '';
for ($i = 1; $i <= 55; $i++) {
$concat_string .= $_POST['C'.$i];
}