Welcome Guest, Not a member yet? Register   Sign In
how to display result_array in php ?
#1

[eluser]mythilisubramanyam[/eluser]
///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>&lt;input type="text" name=""
value="&lt;?php foreach($get as $lang) { echo $lang['dLanguageName']; } ?&gt;"&gt; </td>

<td>&lt;input type="text" name=""
value="&lt;?php foreach($get as $lang) { echo $lang['dLanguageName']; } ?&gt;"&gt; </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

[eluser]hightower[/eluser]
Try this in your view:

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

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 Smile
#3

[eluser]Phil Sturgeon[/eluser]
Looks like he might benefit from a more explicit example.

Code:
&lt;?php foreach($get as $lang): ?&gt;
<td>&lt;input type="text" name="" value="&lt;?php echo $lang['dLanguageName']; ?&gt;"&gt;&lt;/td>
&lt;?php endforeach; ?&gt;
#4

[eluser]mythilisubramanyam[/eluser]
thank u,
any how,i got the solution for that
Code:
<td>&lt;input type=“text” name=””
value=”&lt;?php foreach($get as $lang) { echo $lang[‘dLanguageName’]; } ?&gt;”&gt; </td>

in this i assigned $lang to some arr[] and displayed as arr[0];
Code:
<td>&lt;input type=“text” name=””
value=”&lt;?php foreach($get as $lang) { $arr1[]= $lang; } echo $arr1[0]; ?&gt;”&gt; </td>
#5

[eluser]Johan André[/eluser]
You should read the userguide AND the PHP manual.
This is not a CI-question.
#6

[eluser]Phil Sturgeon[/eluser]
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:

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

That is essentially all your code is doing...




Theme © iAndrew 2016 - Forum software by © MyBB