1
<?php
$fivesdrafts = $wpdb->get_results(" SELECT......");

foreach ( $fivesdrafts as $fivesdraft ) {
    $user_gift = $fivesdraft->recommend_getdetailgift;
    echo $user_gift;
}
?>

Output:

Television
Computer
Mobile

I want to display these values into the below form

<input type="hidden" value="???" name="getallgifts" >

So that I can get that store into $_POST['getallgifts']. In this way, I can send that in email.

Check here the actual code which I'm using in order to achieve my result

UPDATED

$getallgifts = $_POST['getallgifts[]'];
$message = 'Request From : '.$getallgifts.'
------
<form method="post" action="#" class="getfffff" style="text-align:center;">

<?php
$fivesdrafts = $wpdb->get_results( 
    "
    SELECT *
    -----
);

foreach ( $fivesdrafts as $fivesdraft ) 
{
  $user_gift = $fivesdraft->recommend_getdetailgift;
    echo '<input type="hidden" value="' .  $user_gift . '" name="getallgifts[]" >';

}

?>
    <input type="hidden" value="<?php echo $user_sum; ?>" name="getwwitdreawv">
</form>
0

2 Answers 2

1

Try this way

<?php
$fivesdrafts = $wpdb->get_results(" SELECT  ......   ");
foreach ( $fivesdrafts as $key => $fivesdraft ) {
    $user_gift = $fivesdraft->recommend_getdetailgift;
    echo '<input type="hidden" value="' .  $user_gift . '" name="getallgifts[' . $key . ']" >';
}
?>

for retrive the value of the array getallgifts submitted you should try this way

  $getallgifts = $_POST['getallgifts'];
  $message =  'Request From : '

  foreach(  $getallgifts as $gift) {
      $message = $message . $gift;
  }
Sign up to request clarification or add additional context in comments.

20 Comments

doesn't work... both the above and below answer doesn't work.. The output is displaying Array
But you need a distinct getallgifts for each row?
I have update the answer adding a key for the getallgifts array
yes all rows.. your edited code is not even getting output ..$key=> $fivesdraft edit that..
Please check my updated question. Yes I tried with that as well but it didn't work either..
|
1

Change this part:

$user_gift = $fivesdraft->recommend_getdetailgift;
echo $user_gift;

To this:

echo '<input type="hidden" value="'.$fivesdraft->recommend_getdetailgift.'"
 name="getallgifts[]">'

This way, you'll have an element in your $_POST array named [getallgifts] that will have an array inside it, with every instance of this input you'll echo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.