ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

how to display result_array in php ?

July 02, 2009 3:41am

Subscribe [4]
  • #1 / Jul 02, 2009 3:41am

    ///In Controller, i have a code :

    $data[‘get’]=$this->staffModel->getDetails($empid);
    $this->load->view(‘staffProfile’,$data);

    ///In model, query is:

    function getDetails($empid)
    {
    $query = $this->db->query("select * from tbl_emp_language where dEmp_id='$empid' ");
    return $query->result_array();
    }

    //In View :
    <td><input type=“text” name=””
    value=”<?php foreach($get as $lang) { echo $lang['dLanguageName']; } ?>”> </td>

    <td><input type=“text” name=””
    value=”<?php foreach($get as $lang) { echo $lang['dLanguageName']; } ?>”> </td>

    output is “EnglishHindiKannada” in all textbox,

    But i need to separate the languages and display it in each textbox,

    So can any one help me in this issue,

  • #2 / Jul 02, 2009 4:41am

    hightower

    12 posts

    Try this in your view:

    <?php
    foreach ($data as $d)
    {
        echo '<td>' . $d['name'] . '</td>';
    }
    ?>

    Basically, include the <td> and </td> in the foreach statement and they to will be repeated.

    P.S. Use code tags when posting so it’s easier to read your code 😊

  • #3 / Jul 02, 2009 9:11am

    Phil Sturgeon

    2889 posts

    Looks like he might benefit from a more explicit example.

    <?php foreach($get as $lang): ?>
    <td><input type="text" name="" value="<?php echo $lang['dLanguageName']; ?>"></td>
    <?php endforeach; ?>
  • #4 / Jul 02, 2009 9:19am

    thank u,
    any how,i got the solution for that

    <td><input type=“text” name=”” 
    value=”<?php foreach($get as $lang) { echo $lang[‘dLanguageName’]; } ?>”> </td>

    in this i assigned $lang to some arr[] and displayed as arr[0];

    <td><input type=“text” name=”” 
    value=”<?php foreach($get as $lang) { $arr1[]= $lang; } echo $arr1[0]; ?>”> </td>
  • #5 / Jul 02, 2009 9:30am

    Johan André

    412 posts

    You should read the userguide AND the PHP manual.
    This is not a CI-question.

  • #6 / Jul 02, 2009 9:33am

    Phil Sturgeon

    2889 posts

    mythilisubramanyam: that code really is not right. You are doing that three times over for each input?

    Why are you using an array to create an array then output a specific itteration?

    Use a foreach loop properly like I have showed you…

    Or do this:

    <td><input type="text" name="" value=”<?php $get[0]; ?>”> </td>

    That is essentially all your code is doing…

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases