Screenshoot 1 contain all of my data on database table while screenshoot 2 is detail of someone data whenever i click on search icon on screenshoot 1.
What i need is, how to print only someone data without pass the ID/parameter on my url for calling the controller? Btw, im using DOMPDF as my pdf generator.
Here my code :
Model
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();
}
Controller
public function cetakkartu($id) {
//set a value for $kode_pasien
$kode_pasien = $id;
// Load all views as normal
$data['title'] = "Data Pasien | Praktik Dokter Umum";
$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));}
View for all data in my database table (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>
View for my detail data (screenshoot 2)
<div class="box">
<div class="box-body">
<div class="btn-group">
<a href="<?php echo base_url("index.php/a_controller/cetakkartu/4");?>"/>
<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>
Like you see, i need to pass someone ID like this
<a href="<?php echo base_url("index.php/a_controller/cetakkartu/4");?>"/>
<button class="btn-success btn">
Cetak Kartu Berobat</button>
</a>
It will only print someone with ID = 4 , it makes me cant print others person detail data. Did i need to change the ID whenever i want to print someone data? It's really hard.
anyone can help me?
<a href="<?php echo base_url("index.php/a_controller/cetakkartu").$kartu[0]['kode_pasien'];?>"/>
<button class="btn-success btn">
Cetak Kartu Berobat
</button>
</a>
Related
I have two tables in mysql, one table holds pics been snapped from webcam with image descriptions and another table which holds the user's registration details.
The image below will explain better.
This is the photos table with a track_id of the user
This is the user registration table with a unique id
On the the photos table the user details appeared twice with different description of the image uploaded
here is the result of the fetched details from both tables
My objective is to make the pictures appear side by side but when I fetched from database it was duplicating the information due to the fact that the user appeared twice on the photos table. And when I used group by it only displayed one picture.
Here is my source code
<?php require_once('queries.php'); ?>
<?php include("header.php"); ?>
<?php include("head.php"); ?>
<?php include("sidenavs.php"); ?>
<?php include("topnavs.php"); ?>
<div class="wrapper">
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 col-md-12">
<h4 class="form-signin-heading">Users Details.</h4>
<hr />
<span class="glyphicon glyphicon-pencil"></span> Add User
<hr />
<div class="content-loader">
<table cellspacing="0" width="100%" id="example" class="table display table-striped table-hover table-responsive">
<thead>
<tr>
<th>#ID</th>
<th>Name</th>
<th>dob</th>
<th>gender</th>
<th>bvn</th>
<th>business name</th>
<th>contact address</th>
<th>Town/City</th>
<th>lga</th>
<th>State</th>
<th>phone 1</th>
<th>phone 2</th>
<th>email</th>
<th>products & services rendered</th>
<th>sub society name</th>
<th>position</th>
<th>mem id no</th>
<th>next kin name</th>
<th>relationship</th>
<th>phone of next kin</th>
<th>payment status</th>
<th>photo</th>
<th>signature</th>
<th>date registered</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
require_once 'db/dbconfig.php';
$i =1;
$stmt = $db_con->prepare("SELECT * FROM users ORDER BY id DESC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
$idm = $row['id'];
$stmts = $db_con->prepare("SELECT * FROM fotos where track_id ='$idm' group by $idm");
$stmts->execute();
$rows=$stmts->fetch(PDO::FETCH_ASSOC);
?>
<tr>
<td><?php echo $i; $i++;?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['dob'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['bvn'];?></td>
<td><?php echo $row['business_name'];?></td>
<td><?php echo $row['contact_addr'];?></td>
<td><?php echo $row['Town_City'];?></td>
<td><?php echo $row['lga'];?></td>
<td><?php echo $row['State'];?></td>
<td><?php echo $row['phone_1']; ?></td>
<td><?php echo $row['phone_2']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['products_services_rendered'];?></td>
<td><?php echo $row['sub_society_name']; ?></td>
<td><?php echo $row['position']; ?></td>
<td><?php echo $row['mem_id_no'];?></td>
<td><?php echo $row['next_kin_name'];?></td>
<td><?php echo $row['relationship'];?></td>
<td><?php echo $row['phone_of_next_kin'];?></td>
<td><?php if($row['payment_status'] == 'Paid'){echo '<span class="alert-success" style="padding:3px; ">Paid</span>';}else{echo '<span class="alert-warning" style="padding:3px; ">Unpaid</span>';}?></td>
<td><img src="fotos/<?php if($rows['des'] == 'Photo'){echo $rows['id_foto'];}?>" width="50" height="50"></td>
<td><img src="fotos/<?php if($rows['des'] == 'Signature'){echo $rows['id_foto'];} ?>" width="50" height="50"></td>
<td><?php echo $row['date_registered'];?></td>
<td class="td-actions text-right">
<!--<a id="<?php echo $row['id']; ?>" class="edit-link btn btn-primary btn-simple btn-xs" rel="tooltip" href="#" title="Edit User"><i class="material-icons">edit</i></a>-->
<a id="<?php echo $row['id']; ?>" class="delete-link btn-danger btn-simple btn-xs" rel="tooltip" href="#" title="Delete">
<span class="glyphicon glyphicon-trash"></span>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php include("footer2.php"); ?>
First I will tell what I want to achieve, and then I will explain how I was trying to do it.
I have two tables, one stores type of vessels with a description and their own Id. Then I have another table in wich the vessel type has been stored as text. My goal is to select each one (both records in both tables) with a checkbox in both and store in the table 2 the Id from the table 1.
I will introduce data, to help.
Table 1
1|Balandra|Some description
2|Bergantin|Some description
3|Whatever |Whatever.....
Table2
Balandra
Bergantin
Whatever
Then, I have created a php page that shows both tables with the checkbox I mentioned above. Checkboxes store the Table1 Id and Table2 vesseltypename.
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<a href=<?php echo '../vista/modificar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
pencil"></em></a>
<a href=<?php echo '../datos/borrar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
trash"></em></a>
</td>
<td class="hidden-xs"><?php echo
$navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid" value=<?
php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body paneltodo">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
So, I want to check both table records and store the table1 Id in the table2 idtypevessel field.
I thought that a php file could store both items and call the update function with those parameters, like this:
<?php
require './modelo.php';
$idnavio = $_GET['agruparid'];
$vessel = $_GET['agruparvessel'];
Any suggestions, because I think I have to do a button to submit this parameters, but it must be working on both tables, and I don't know how to access both foreach loop at the same time.
Thanks in advance.
E. Salas
review bellow reference code to submit multi selected checkbox values
for multi selected checkbox submission you must use [] operator after name attribute in html
index.php
<form action="/checkbox.php" method="post">
<strong>Cars:</strong><br>
<?php
$cars = array("Volvo", "BMW", "Toyota");
$colors = array("Red", "Green", "Black");
foreach($cars as $single){
?>
<input type="checkbox" name="cars[]" value="<?php echo $single; ?>">
<?php
}
<br>
<strong>colors:</strong><br>
foreach($colors as $single){
?>
<input type="checkbox" name="colors[]" value="<?php echo $single; ?>">
<?php
}
?>
<br>
<input type="submit" value="Submit!">
</form>
checkbox.php
<?php
echo "<pre>";
var_dump($_POST);
exit;
In your case:
<form action="/checkbox.php" method="post">
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-pencil"></em>
<em class="fa fa-trash"></em>
</td>
<td class="hidden-xs"><?php echo $navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid[]" value=<?php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel[]" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<input type="submit" value="Submit!">
</form>
Finally I solved this with Javascript. One of my partners helped me, I post this to help people in my situation.
I created a script, here is the code:
<script type="text/javascript">
function cogeNavioDyncoopnet(){
var checkedValueNavioD = null;
var inputElements = document.getElementsByClassName('checknaviod');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioD = inputElements[i].value;
break;
}
}//return checkedValueNavioD;
var input_nav_dyn = document.getElementById("nav_dyn");
input_nav_dyn.value = checkedValueNavioD;
}
function cogeNavioForSea(){
var checkedValueNavioFs = null;
var inputElements = document.getElementsByClassName('checknaviofs');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioFs = inputElements[i].value;
break;
}
}//return checkedValueNavioFs;
var input_nav_fs = document.getElementById("nav_fs");
input_nav_fs.value = checkedValueNavioFs;
}
</script>
Then I created a Form below, that collects values and sends them to my .php control file.
<div class="hidden-xs">
<form class="hidden-xs" method="POST"
action="../datos/actualizarnavios.php">
<input id="nav_dyn" type="text" name="idnaviodyncoop">
<input id="nav_fs" type="text" name="navioforsea" >
<input id="botonasignar" type="submit" name="enviardatosdynfs">
</form>
</div>
I hope this helps. Thanks for the feedback, as always.
I have got an ebooks table in the database where path of pdf is defined.What I want is, when a user clicks on the download button, pdf get download.But the download button is not working and I'm also not getting any error from Php.Please help! Thank you.
Code:
<div id="data">
<?php
if (isset($_POST['submit'])) {
$title = $_POST['title'];
$name = $_POST['name'];
$count = 1;
$query = "SELECT * FROM ebooks WHERE $title LIKE '%".$name."%'";
$display = $obj->run_query($query);
?>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr align="center">
<td>No.</td>
<td>Title</td>
<td>Author</td>
<td>Publication</td>
<td>Status</td>
</tr>
</thead>
<tbody>
<?php
foreach ($display as $key) { ?>
<tr align="center">
<td><?php echo $count++;?></td>
<td><?php echo $key['ebook_title'];?></td>
<td><?php echo $key['ebook_author'];?></td>
<td><?php echo $key['ebook_publication'];?></td>
<td><a style="color:white;" href="/admin/ebooks/<?php echo $key['ebook_url'];?>" class="btn btn-round btn-primary">Download</a></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } ?>
</div>
</div>
You have to add download before ending of anchor tag try this :
<a style="color:white;" href="/admin/ebooks/<?php echo $key['ebook_url'];?>" class="btn btn-round btn-primary" download>Download</a>
The following code is showing only the record list and i want when we click on a link then it go to another page which will suppose to show only the record details of a selected title. Currently, it always shows the same details. now what is the solution of show only the records details of a selected title
<table class="table table-striped table-bordered bootstrap-datatable datatable">// the record list table
<thead>
<tr>
<th>ID</th>
<th>Course Name</th>
<th>Duration</th>
<th>Subjects</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $getcourseslist = find_all("select * from course");
while(#$getcourses = fetch_array($getcourseslist)){
?>
<tr>
<td><?= $getcourses->id; ?></td>
<td> <?= $getcourses->title;?></td>
<td><?= $getcourses->duration/12; ?> Years</td>
<td class="center">
<?php $getsubjects= find_all("select * from subjects where courseid='$getcourses->id'");
while(#$getsubs = fetch_array($getsubjects)){
?>
<?= $getsubs->name; ?><br>
<?php } ?>
</td>
<td class="center">
<?php if($getcourses->status == 1){ ?>
<span class="label label-success">Active</span>
<?php }
else{
?>
<span class="label label-important">Blocked</span>
<?php } ?>
</td>
<td class="center">
<a class="btn btn-success" href="editcourse.php?course=<?= $getcourses->id; ?>">
<i class="halflings-icon white edit"></i>
</a>
<?php if($getcourses->status == 1){ ?>
<a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=block&&page=courses">
<i class="halflings-icon white trash"></i>
</a>
<?php }
else{
?>
<a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=unblock&&page=courses">
<i class="halflings-icon white trash"></i>
</a>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div><!--/span-->
</div><!--/row-->
// The following code is supposed to show only the record details of a selected title. Currently, it always shows the same detail list of previous page.//
Course Details View
<tr>
<th>ID :</th>
<td><?= $getcourses2->id; ?></td>
</tr>
<tr>
<th>Course Name :</th>
<td><?= $getcourses2->title; ?></td>
</tr>
<tr>
<th>Duration :</th>
<td><?= $getcourses2->duration/12; ?> Years</td>
</tr>
<tr>
<th>Subjects :</th>
<td class="center">
<?php $getsubjects= find_all("select * from subjects where courseid='$getcourses->id'");
while(#$getsubs = fetch_array($getsubjects)){
?>
<?= $getsubs->name; ?><br>
<?php } ?>
</td>
</tr>
<tr>
<th>Monthly Fee :</th>
<td><?= $getcourses2->monthlyfee ; ?></td>
</tr>
<tr>
<th>Examination Fee :</th>
<td><?= $getcourses2->examinationfee; ?></td>
</tr>
<tr>
<th>Addmission Fee :</th>
<td><?= $getcourses2->addmissionfee; ?></td>
</tr>
<tr>
<th>Status :</th>
<td class="center">
<?php if($getcourses2->status == 1){ ?>
<span class="label label-success">Active</span>
<?php }
else{
?>
<span class="label label-important">Blocked</span>
<?php } ?>
</td>
</tr>
<tr>
<th>Actions :</th>
<td class="center">
<a class="btn btn-success" href="editcourse.php?course=<?= $getcourses->id; ?>">
<i class="halflings-icon white edit"></i>
</a>
<?php if($getcourses2->status == 1){ ?>
<a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=block&&page=courses">
<i class="halflings-icon white trash"></i>
</a>
<?php }
else{
?>
<a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=unblock&&page=courses">
<i class="halflings-icon white trash"></i>
</a>
<?php } ?>
</td>
</tr>
<?php } ?>
</thead>
<tbody>
</table>
enter code here
change the table titles contents to anchor tags
for example as
ID
and then in server side , process the query as
$sort = 'id';
if(isset($_REQUEST['sortby'])&&str_replace(' ','',$_REQUEST['sortby'])!="") $sort = $_REQUEST['sortby'];
$queryText= "select * from table_name where order by ".$sort;
make sure that the value passed by the href is the attribute name in your sql table
this code makes the query to work as sorted default by id.. if a user uses another title, it will switch as needed.
hopes this works..
NOTE: people interested in down voting, please specify the reason
Heres my code: HTML with Server side to get data from the database. How do I get id from the datatables using checkbox option?
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<h4>
<th></th> <!-- For checkbox column-->
<th>ID Number</th>
<th>Lastname</th>
<th>Firstname</th>
<th>Middlename</th>
<th>Gender</th>
<th>Course</th>
<th>Department</th>
<th>Address</th>
<th>Contact</th>
<th>Birthdate</th>
<th>View</th>
<th>Events</th>
</h4>
</tr>
</thead>
<tbody>
<?php
include 'pgconnect.php';
$mydata = mysqli_query($conn,"SELECT * FROM student") or die(mysql_error());
while($record = mysqli_fetch_assoc($mydata))
{
$id=$record['id'];
?>
<tr>
<td><input type="checkbox"></td>
<td class="id"><?php echo $record['id'] ?></td>
<td class="lname"><?php echo $record['last_name'] ?></td>
<td class="fname"><?php echo $record['first_name'] ?></td>
<td class="mname"><?php echo $record['mid_name'] ?></td>
<td class="sex"><?php echo $record['gender'] ?></td>
<td class="course"><?php echo $record['course'] ?></td>
<td class="dept"><?php echo $record['department'] ?></td>
<td class="add"><?php echo $record['home_address'] ?></td>
<td class="contact"><?php echo $record['contact'] ?></td>
<td class="bdate"><?php echo $record['birthdate'] ?></td>
<td> View Records </td>
<td> <a title='Click here to update record.'href='#edit' data-toggle='modal'><i class="fa fa-pencil fa-fw"></i></a>
<a title='Click here to add record.' href='#'><i class="fa fa-plus fa-fw"></i></a>
<a title='Click here to delete record.' href='delete.php?del=<?php echo $record['id'] ?>'><i class="fa fa-trash-o fa-fw"></i></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
Here's my script:
$(document).ready(function(){
$('#dataTables-example').dataTable();
});
I tried to get the ID but still it didn't works. Hope you can help me.
In your work, you get the ID in table. your should grab it from the checkbox if you use jquery, as in;
<script>
$(document).ready(function(){
document.getElementByID("ckmyid").innerHTML;
});
</script>
Note:add Selector ID in your checkbox, first, say, "ckmyid" so the code will be like this:
<input id="ckmyid" type="checkbox" value="<?php echo $record['id'] ?>">
Based on your structure, you can grab it directly from the link in your view records link if you want to place the ID there,as in;
<td> View Records </td>