开发者

storing multiple values in a single variable?

<form action="" method="post">
<input type="submit" name="foo" value="A" />
<input type="submit" name="foo" value="B" />
<input type="submit" name="foo" value="C" />
<input type="submit" name="foo" value="D" />
</form开发者_StackOverflow>

<?php
  $letters = $_POST['foo'];
?>

each time form submit $letters will be filled with respective values. so $letters can be "A" or "B" or "C" etc.

is it possible store all submitted values at a time? say when I echo $letters it should give "ABCD" or "BCDBA" or whatever order form is submitted.

I think this can be done through $_SESSION but no Idea how...any ideas?


Hy Try make the attribute name in each submit button: name="foo[]" Then, in php, $_POST['foo'] contains an array with the value of each "foo[]"

echo implode('', $_POST['foo']);


You could use the session, so first: $_SESSION['letters']=array(); and then each post you can do $_SESSION['letters'][] = $_POST['foo']; and then you will have an ordered array.

This is how the top of your page will look:

session_start(); //important that this is first thing in the document
if ( !$_SESSION['letters'] ) {
    $_SESSION['letters'] = array(); //create the session variable if it doesn't exist
}
if ( $_POST['foo'] ) { //if foo has been posted back
    $_SESSION['letters'][] = $_POST['foo'];  // the [] after the session variable means add to the array
}

You can use print_r $_SESSION['letters']; to output the array as a string, or you can use any of the many php array functions to manipulate the data.


Try this

$email_to = "";
$get= mysql_query("SELECT * FROM `newsletter`");

while ($row = mysql_fetch_array($get)) {
    $email_to = $email_to.",".$row['mail'];
}

echo $email_to;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜