0

I have problem in my view display in codeigniter

I have a problem with my database display in the 'view' in CodeIgniter, I've been able to do load my database and display data using tables, but the data is performed by using extends vertically downwards by using a row, whereas I want to display it horizontally by using column

[my view display in browser]
[data 1]
[data 2]
[data 3]
[etc...]

my view I wanted!
[data 1] [data 2] [data 3] [etc..]

this is my Controller Code:

function coba(){
    // nyobain nge load td secara multiple
$data['query'] = $this->Latihan_model->coba()->result();
$this->load->view('rubbish/coba',$data);
}

this is my model Code:

function coba(){
$sql = ("
    SELECT soal.ID_soal as soal
    from soal
    where soal.ID_bagian = 1;
    "); return $this->db->query($sql);
}

this is my view code:

<table border=1>
<?php foreach($query as $post): ?>
<tr>
    <td><? echo $post->soal; ?></td>
</tr>
<?php endforeach; ?>

I hope you're understand what I am asked

2
  • Move the tr outside foreach? Commented May 25, 2014 at 16:26
  • I input my answers. Wish that will help for you. Commented May 25, 2014 at 16:39

2 Answers 2

1

You can try this

<table border=1>
<tr>
<?php foreach($query as $post): ?>
    <td><? echo $post->soal; ?></td>
<?php endforeach; ?>
</tr>
Sign up to request clarification or add additional context in comments.

Comments

0

try this:

<?php foreach($query as $key => $value): ?>
<tr>
   <?php foreach($key as $val): ?>
       <td><?php echo $val; ?></td>
   <?php endforeach; ?>
</tr>
<?php endforeach; ?>

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.