打印/显示一行只从我的表[Codeigniter] [英] print/show one row only from my table [Codeigniter]
问题描述
我尝试打印我的数据从我的数据库表与spesific行。让我们说,我在我的表中有这样的数据:
I try to print my data from my database table with spesific row. lets say, i have data in my table like this :
kode_pasien = 1,name_pasien = john,email_pasien=john@xxx.com, alamat_pasien = denpasar
kode_pasien = 2,name_pasien = mark,email_pasien=mark@xxx.com,alamat_pasien = bandung
kode_pasien = 3,name_pasien = diana,email_pasien = diana @ xxx。 com,alamat_pasien = surabaya
kode_pasien=1, name_pasien=john, email_pasien=john@xxx.com, alamat_pasien=denpasar
kode_pasien=2, name_pasien=mark, email_pasien=mark@xxx.com, alamat_pasien=bandung
kode_pasien=3, name_pasien=diana, email_pasien=diana@xxx.com, alamat_pasien=surabaya
并且我只想显示Diana的资料我的表格。
这是我的下列代码
模型
public function view_kartu($kode_pasien)
{
$query = $this->db->query("SELECT * FROM tb_pasien where kode_pasien='$kode_pasien' LIMIT 1");
return $query->result_array();
}
控制器
public function cetakkartu() {
//set a value for $kode_pasien
$kode_pasien = "1";
// Load all views as normal
$data['kartu_pasien'] = $this->a_model->view_kartu($kode_pasien);
$this->load->view('cetak-kartu', $data);
// Get output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
// Convert to PDF
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream("cetak-kartu" . ".pdf", array ('Attachment' => 0));
}
查看cetakkartu打印 / p>
View for cetakkartu print
<table width="40%">
<?php foreach ($kartu_pasien as $v): ?>
<tr>
<th>KARTU BEROBAT</th>
<th>PRAKTIK DOKTER</th>
</tr>
<tr>
<td>Kode Pasien</td>
<td> : <?php echo $v['kode_pasien']?></td>
</tr>
<tr>
<td>Nama Pasien</td>
<td> : <?php echo $v['nama_pasien']?></td>
</tr>
<tr>
<td>Email Pasien</td>
<td> : <?php echo $v['email_pasien']?></td>
</tr>
<tr>
<td>Alamat Pasien</td>
<td> : <?php echo $v['alamat_pasien']?></td>
</tr>
<tr>
<td>Tanggal Lahir</td>
<td> : <?php echo $v['tanggal_lahir']?></td>
</tr>
<tr>
<td>Umur</td>
<td> : <?php echo $v['umur']?></td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td> : <?php echo $v['kode_jk']?></td>
</tr>
<tr>
<td>No. Telp</td>
<td> : <?php echo $v['no_telp']?></td>
</tr>
<tr>
<td> <i>*Wajib dibawa setiap datang untuk berobat</i></td>
</tr>
<?php endforeach; ?>
</table>
查看有关某人详细资料的表单(请参阅第2页)
每当我点击在屏幕上的搜索图标1时会显示
View form for someone detail data (see screenshoot 2)
It will show whenever i click on search icon on screenshoot 1
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-6">
<div class="box">
<div class="box-body">
<div class="btn-group">
<a href="<?php echo base_url("index.php/a_controller/cetakkartu");?>"/>
<button class="btn-success btn">
Cetak Kartu Berobat</button>
</a>
</div>
<br>
<br>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<?php
if(isset($kartu)){
$no=0; foreach ($kartu as $isi): $no++;
# code...
?>
<tr>
<td>Kode Pasien</td>
<td><?php echo $isi->kode_pasien?></td>
</tr>
<tr>
<td>Nama Pasien</td>
<td><?php echo $isi->nama_pasien?></td>
</tr>
<tr>
<td>Email Pasien</td>
<td><?php echo $isi->email_pasien?></td>
</tr>
<tr>
<td>Alamat Pasien</td>
<td><?php echo $isi->alamat_pasien?></td>
</tr>
<tr>
<td>Tanggal Lahir</td>
<td><?php echo $isi->tanggal_lahir?></td>
</tr>
<tr>
<td>Umur</td>
<td><?php echo $isi->umur?></td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td><?php echo $isi->kode_jk?></td>
</tr>
<tr>
<td>No. Telp</td>
<td><?php echo $isi->no_telp?></td>
</tr>
<?php endforeach;}?>
</table>
</div>
</div>
</div>
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
View for my screenshoot 1
<div class="box">
<div class="box-body">
<div class="btn-group">
<a href="<?=base_url();?>index.php/a_controller/regismanual"/>
<button class="btn-success btn">
Tambah Pasien</button>
</a>
</div>
<br>
<br>
<div class="table-responsive">
<table id="rekam" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Kode Pasien</th>
<th>Nama Pasien</th>
<th>Email Pasien</th>
<th>Alamat Pasien</th>
<th>Tanggal Lahir</th>
<th>Umur</th>
<th>JK</th>
<th>No. Telp</th>
<th>Opsi</th>
</tr>
</thead>
<tr>
<tbody>
<?php
if(isset($pasien)){
$no=0; foreach ($pasien as $isi): $no++;
# code...
?>
<td><?php echo $isi->kode_pasien?></td>
<td><?php echo $isi->nama_pasien?></td>
<td><?php echo $isi->email_pasien?></td>
<td><?php echo $isi->alamat_pasien?></td>
<td><?php echo $isi->tanggal_lahir?></td>
<td><?php echo $isi->umur?></td>
<td><?php echo $isi->kode_jk?></td>
<td><?php echo $isi->no_telp?></td>
<td>
<a href="<?=base_url()?>index.php/a_controller/updatepasien/<?php echo $isi->kode_pasien?>">
<button type="button" class="btn-success btn"><span class="glyphicon glyphicon-pencil"></span></button>
</a>
<a href="<?=base_url()?>index.php/a_controller/deletepasien/<?php echo $isi->kode_pasien?>" onclick="return confirm('Apakah anda yakin akan menghapus data ini?')">
<button type="button" class="btn-inverse btn"><span class="glyphicon glyphicon-trash"></span></button>
</a>
<a href="<?=base_url()?>index.php/a_controller/detail/<?php echo $isi->kode_pasien?>">
<button type="button" class="btn-warning btn"><span class="glyphicon glyphicon-search"></span></button>
</a>
</td>
</tr>
</tbody>
<?php endforeach;}?>
</table>
</div>
</div>
</div>
我认为我的模型或控制器有问题。因为在控制器上我设置了这样
I think i have problem with my model or controller. Because on controller i set something like this
$ kode_pasien =1
,因为只要我打印某人的数据,就只显示John的数据。
$kode_pasien = "1"; because whenever i want to print someone data, it will only show John's data.
有人可以帮我解决?我应该怎么做我的控制器/模型? Thankyou
Can someone help me to solve it? What should i do with my controller/model? Thankyou
推荐答案
/* =====If You want only a specific row from the table do it like=====*/
**=====In your model==========**
$query = $this->db->query("YOUR QUERY");
$row = $query->row();// replace this
$row = $query->row(3); // by this one
if (isset($row))
{
echo $row->title;
echo $row->name;
echo $row->body;
}
这篇关于打印/显示一行只从我的表[Codeigniter]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!