1

when i get the data by id, just only display first row from table

This is my controller

public function getDetail($id=true)
{

    $data['detail'] = $this->vendor_model->getDetail($id);
    $this->load->view('vendor/detailvendor',$data);

}

this is my model

 public function getDetail($id)
{

    $this->db->where('no_spk',$id);
    $query = $this->db->query("select a.no_spk, a.nama_pekerjaan, a.alamat, a.latitude, a.longitude, b.nama_vendor, c.progress, c.keterangan, c.gambar, c.gambar2, c.gambar3, d.namapekerja from vendor as b inner join pekerjaan as a on b.id_vendor = a.id_vendor inner join progress as c on c.no_spk = a.no_spk inner join pekerja as d on d.id_pekerja=c.id_pekerja");
    return $query->result();
}

And, this is my view

<?php echo form_open_multipart('homevendor/getDetail'.$this->uri->segment(4)); ?>
<?php echo $detail[0]->no_spk?><br>
<?php echo $detail[0]->nama_pekerjaan?><br>
<?php echo $detail[0]->progress?><br>
<?php echo form_close();?>

the result isview on website content of table, there are 2 data but only show first data

please help me

2 Answers2

1

1.For getting and showing all records, only change view file code like below:-

 <?php echo form_open_multipart('homevendor/getDetail'.$this->uri->segment(4)); ?>
  <?php foreach($detail as $deta){?>
    <?php echo $deta->no_spk?><br>
    <?php echo $deta->nama_pekerjaan?><br>
    <?php echo $deta->progress?><br>
  <?php }?>
<?php echo form_close();?>

2.For getting and showing single records, use LIMI 1 in query and change view code also like below:-

Modal code:-

public function getDetail($id){
   $this->db->where('no_spk',$id);
   $query = $this->db->query("select a.no_spk, a.nama_pekerjaan, a.alamat, a.latitude, a.longitude, b.nama_vendor, c.progress, c.keterangan, c.gambar, c.gambar2, c.gambar3, d.namapekerja from vendor as b inner join pekerjaan as a on b.id_vendor = a.id_vendor inner join progress as c on c.no_spk = a.no_spk inner join pekerja as d on d.id_pekerja=c.id_pekerja LIMIT 1");
   return $query->result();
}

And view:-

<?php echo form_open_multipart('homevendor/getDetail'.$this->uri->segment(4)); ?>
  <?php foreach($detail as $deta){?>
    <?php echo $deta->no_spk?><br>
    <?php echo $deta->nama_pekerjaan?><br>
    <?php echo $deta->progress?><br>
  <?php }?>
<?php echo form_close();?>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • 1
    give me a minute to try that –  Feb 21 '18 at 07:36
  • 1
    by the way thankyou because u help me, i got error because my mistake on button "DETAIL" typo :))) but thankyou your very is very help me to code next time –  Feb 21 '18 at 12:38
0
    public function getDetail($id)
{

    //$this->db->where('no_spk',$id);
    $query = $this->db->query("select a.no_spk, a.nama_pekerjaan, a.alamat, a.latitude, a.longitude, b.nama_vendor, c.progress, c.keterangan, c.gambar, c.gambar2, c.gambar3, d.namapekerja from vendor as b inner join pekerjaan as a on b.id_vendor = a.id_vendor inner join progress as c on c.no_spk = a.no_spk inner join pekerja as d on d.id_pekerja=c.id_pekerja WHERE c.no_spk=".$id);
    return $query->row();
}

View

<?php echo form_open_multipart('homevendor/getDetail'.$this->uri->segment(4)); ?>
<?php echo $detail->no_spk?><br>
<?php echo $detail->nama_pekerjaan?><br>
<?php echo $detail->progress?><br>
<?php echo form_close();?>

Explanation

You are looking for to fetch a single row.Use row function instead of result. Codeigniter database class row function returns an object. SO you will be able to use the -> to accessing the object data.

Adnan Haider
  • 265
  • 5
  • 16
  • i will try that, give me a minute –  Feb 21 '18 at 06:02
  • I updated my answer just copy the model function and paste it again. – Adnan Haider Feb 21 '18 at 06:03
  • by the way thankyou because u help me, i got error because my mistake on button "DETAIL" typo :))) but thankyou your very is very help me to code next time –  Feb 21 '18 at 12:38
  • by the way help me to upload multiple images, i was post my question but i'm still confused @Adnanhaider –  Feb 22 '18 at 01:26
  • I don't know your exact question. But check this link before posting any question. https://stackoverflow.com/questions/24895170/multiple-image-upload-php-form-with-one-input – Adnan Haider Feb 22 '18 at 04:47