Charlie Brown Charlie Brown - 1 year ago 79
PHP Question

How to show all received array result from input array value in codeigniter

Hi I'm working in codeigniter. I want to show all array passed from an input into my email html format. But now only show 1 item name only, how to show all the item name. Thank you


$details = $this->transaction_detail->get_all_by_header($trans->id)->result();

foreach($details as $value)
echo '<input type="hidden" name="itemname" value="'. $this->item->get_info($value->item_id)->name. '">';


Received the array and put into email function

public function send_mail()

$config['newline'] = "\r\n";

$from_email = "";
$to_email = $this->input->post('email');

// Only show one item only, how to show all the result array item name

$itemname = $this->input->post('itemname');

$html = "Item Name :" . $itemname . "<br>" .

//Load email library
$this->email->from($from_email, '');
$this->email->subject(" - Completed Order");

//Send mail

if ($this->email->send()) {
$this->session->set_flashdata("email_sent", "Email sent successfully.");
return true;
} else {
$this->session->set_flashdata("email_sent", "Error in sending Email.");
return false;


Answer Source

I can only guess hows your app working, but first, I would make your input an array.

echo '<input type="hidden" name="itemname[]" value="'. $this->item->get_info($value->item_id)->name. '">';

And then correct controller a little:

$html = '';
$items = $this->input->post('itemname[]');//or without square brackets
foreach ($items as $item) {
    $html .= "Item Name :" .  $item. "<br>" .
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download