php ajax search does not show results - php

I am working in a accounting system, then i want display the users when search by lastname or document, here is my
search.php
$busqueda = $_POST['busqueda'];
mysql_select_db($database_connectBD_fc, $connectBD_fc);
//busqueda por cedula
$query_registroClientes = "SELECT * FROM clientes WHERE num_documento LIKE '".$busqueda."' ORDER BY apellidos,nombres";
$registroClientes = mysql_query($query_registroClientes, $connectBD_fc) or die(mysql_error());
$row_registroClientes = mysql_fetch_assoc($registroClientes);
//busqueda por nombre
$query_busquedaClientes = "SELECT * FROM clientes WHERE apellidos LIKE '%".$busqueda."%' ORDER BY apellidos,nombres";
$busquedaClientes = mysql_query($query_busquedaClientes, $connectBD_fc) or die(mysql_error());
$row_busquedaClientes = mysql_fetch_assoc($busquedaClientes);
?>
<?php
include 'dbc.php';
page_protect();
?>
<?php if($row_busquedaClientes==0){
echo "<p class='text-success'>Búsqueda por apellido(s)</p>";?>
<table class="tablas container-fluid">
<tr class="tabla1 row">
<td class="col-md-2">Apellidos</td>
<td class="col-md-2 c-borde">Nombre</td>
<td class="col-md-3">Correo Electronico</td>
<td class="col-md-2 c-borde">Teléfono</td>
<td class="col-md-1">Fecha ingreso</td>
<td class="col-md-1 c-borde">Activo</td>
<td class="col-md-1">Acciones</td>
</tr>
<?php do { ?>
<tr class="info row">
<td style="text-transform:Capitalize;"><strong><?php echo $row_busquedaClientes['apellidos']; ?></strong></td>
<td class="c-borde" style="text-transform:Capitalize;"><?php echo $row_busquedaClientes['nombres']; ?></td>
<td><?php if($row_busquedaClientes['correo'] == False){
echo "<div class='label label-danger'><strong>No hay correo asignado.</strong></div>";
}else{
echo $row_busquedaClientes['correo'];
} ?></td>
<td class="c-borde"><?php echo $row_busquedaClientes['telefono']; ?></td>
<td><?php echo $row_busquedaClientes['fecha_ingreso']; ?></td>
<td class="c-borde">
<?php
if($row_busquedaClientes['activo']=="1"){
echo "<span class='label label-success'>Si</div>";
}
else if($row_busquedaClientes['activo']=="0"){
echo "<span class='label label-danger'>No</div>";} ?>
</td>
<td>
<?php
if($row_busquedaClientes['idCliente']==""){echo " ";}
else{?>
<a href="clientesActualizar.php?num_cliente=<?php echo $row_busquedaClientes['idCliente']; ?>">
<i class="fa fa-pencil-square-o" title="Editar" style="color: #A5C63B; font-size: 20px;"></i>
</a>
<a href="clientesDetalles.php?num_cliente=<?php echo $row_busquedaClientes['idCliente']; ?>">
<i class="fa fa-eye" title="Ver detalles" style="color: #A5C63B; font-size: 20px;border:1px solid; border-width:0px 1px;padding:0 10px;"></i>
</a>
<a onclick="Borra('<? echo $row_busquedaClientes['idCliente']; ?>');" href="#">
<i class="fa fa-trash-o" title="Eliminar" style="color: #dd2e3e; font-size: 20px;"></i>
</a>
<?php } ?>
</td>
</tr>
<?php } while ($row_busquedaClientes = mysql_fetch_assoc($busquedaClientes)); ?>
</table> <?php } ?>
<?php
mysql_free_result($busquedaClientes);
?>
the idea is take the information the user and display in another page where i show all the users who are in the data base, here is where i show the search result
<div class="container botones-busqueda col-md-12">
<div class="container">
<div class="col-md-6">
<a class="btn btn-danger btn-nuevo-cliente" href="clientesNew.php" role="button">Nuevo Cliente</a>
<a class="btn btn-warning" href="vencimientos.php" role="button">Proximos a vencer</a>
<a class="btn btn-default" href="vencidos.php" role="button">Vencidos</a>
</div>
<div class="col-md-3 col-md-offset-3">
<form name="busqueda" id="busqueda" method="post" action="">
<input type="text" name="busquedas" id="busquedas" style="color:black;" placeholder="Buscar, por apellidos">
<input title="Buscar" class="fa fa-search" id="buscar" type="submit" value="Buscar">
<label for="cedula"></label>
</form>
<?php
if (isset($_GET['msg'])) {
echo "<div class=\"error\">$_GET[msg]</div>";
}
?>
</div>
</div>
</div>
<section class="container">
<div id="resultado"></div>
</section>
is where i display all the users, using the code <?php do{} while ($row_registroClientes = mysql_fetch_assoc($registroClientes)); ?> inside display all the users, well i hope someone can help me.
here is my ajax code
<script language="JavaScript">
function Borra(idcontacto)
{
var agree=confirm("¿Realmente desea eliminar el contacto seleccionado?");
if (agree) { document.location="clientesDel.php?num_cliente="+idcontacto; }
else return false ;
}
$(function(){
$('#busquedas').focus();
$('#busqueda').submit(function(e){
e.preventDefault();
})
$('#busquedas').keyup(function(){
var envio = $('#buscar').val();
$('#resultado').html('<p class="text-success">Buscando al cliente.</p>');
$.ajax({
type: 'POST',
url: 'busqueda.php',
data: ('busqueda='+envio),
success: function(resp){
if (resp!="") {
$('#resultado').html(resp);
}
}
})
})
})
</script>
Thanks you.

Related

Ajax success function does not work. checkbox data will not be deleted without hard refresh

I'm using Jquery and Ajax method to delete my data using the checkbox. I'm not sure why my data will not delete without a hard refresh. The success function in Ajax doesn't seem working. I do not know what's the problem here. Can someone kindly help me with this problem?
<script type="text/javascript">
$(document).ready(function(){
$('#btn_delete').click(function(){
// if(confirm("Are you sure you want to delete these products?"))
// {
var id=[];
$(':checkbox:checked').each(function(i){
id[i] = $(this).val();
});
if(id.length === 0){
alert("Please select at least one product");
}else if (confirm("Are you sure you want to delete these products?")){
$.ajax({
url:'includes/delete-in-bulk.php',
method:'POST',
data:{id:id},
success:function(){
for(var i=0; i<id.length; i++){
$('tr#'+id[i]+'').css('background-color','#ccc');
$('tr#'+id[i]+'').fadeOut('slow');
}
}
});
}
else{
return false;
}
});
});
</script>
Here are my PHP codes
<tbody id="products">
<?php
if (!$tot_products) {
echo '
<div class="col-12">
<div class="badge badge-danger">No Products Found</div>
</div>
';
} else {
$i = 1;
while ($row = $query->fetch_assoc()) {
?>
<tr>
<td>
<input type="checkbox" id="checkItem" name="product_id[]" class="delete_products"value="<?php echo $row["product_id"]; ?>">
</td>
<td>
<img src="images/product-main/<?php echo !empty($row['product_photo']) ? $row['product_photo'] : ''; ?>" style="height: 50px; width: 50px;">
</td>
<td>
<?php echo $row['product_title']; ?>
</td>
<td>
<?php echo $row['product_sku']; ?>
</td>
<td>
<?php echo !empty($row['seller_fullname']) ? $row['seller_fullname'] : 'N/A'; ?>
</td>
<td>
<?php echo !empty($row['product_price']) ? $row['product_price'] : 'N/A'; ?>/<?php echo !empty($row['product_unit']) ? $row['product_unit'] : ''; ?>
</td>
<td>
<?php echo !empty($row['product_created']) ? $row['product_created'] : 'N/A'; ?>
</td>
<td>
<?php echo !empty($row['product_stock']) ? $row['product_stock'] : 'N/A'; ?> <?php echo !empty($row['product_unit']) ? $row['product_unit'] : ''; ?>
</td>
<td>
<?php echo ($row['product_status'] != 0) ? '<b class="text-success">In Stock</b>' : '<b class="text-danger">Out of Stock</b>'; ?>
</td>
<td>
<a class="text-primary" href="view-product.php?pid=<?php echo $row['product_id']; ?>" style="text-decoration: none;" title="View Product">
<i class="fa fa-eye"></i>
</a> 
<a class="text-danger" href="includes/delete-product.php?pid=<?php echo $row['product_id']; ?>" style="text-decoration: none;" title="Delete Product" onclick="return confirm('Are you sure want to delete this product?');">
<i class="fa fa-trash-o"></i>
</a>
</td>
</tr>
<!-- The Modal -->
<div class="modal hide fade in" role="dialog" aria-hidden="true" id="productstatus_modal<?php echo $i; ?>">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<!-- Modal body -->
<div class="modal-body">
<div class="float-right mb-3">
<button type="button" class="close" data-dismiss="modal" style="color:#ed1c25;">×</button>
</div>
<div class="mt-5 col-12">
<p class="font-weight-bold mb-3">Product Name: <?php echo $row['product_title']; ?></p>
<form action="includes/product-details.php" method="POST">
<div class="form-group">
<label><b>Change Product Status</b></label>
<select name="product_status" class="form-control product_status" required>
<option disabled selected>Select Option</option>
<option value="1" <?php if($row['product_status'] == 1) { echo ' selected="selected"'; } ?> >In Stock</option>
<option value="0" <?php if($row['product_status'] == 0) { echo ' selected="selected"'; } ?> >Out of Stock</option>
</select>
</div>
<div class="form-group">
<label><b>Product Stock <?php echo !empty($row['product_unit']) ? 'in ' .$row['product_unit'] : ''; ?></b></label>
<input type="number" step="any" placeholder="Enter your Stock" name="product_stock" class="form-control textInput" />
</div>
<div class="float-right">
<input type="hidden" value="<?php echo $row['product_id']; ?>" name="product_id">
<button type="submit" name="chg_prod_status" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
$i++;
}
}
?>
</tbody>
</table>
</div>
</div>
<div class="d-flex p-4 justify-content-around">
<div class="row">
<button type="button" name="btn_delete" id="btn_delete" onClick="window.location.href=window.location.href" value="True" class="btn btn-danger btn-icon-split m-2">
<span class="icon text-white-50">
<i class="fa fa-trash-o"></i>
</span>
<span class="text">Delete Product</span>
</button>
</div>
</div>
here is my delete-in-bulk.php codes
<?php
include '../session.php';
if(isset($_POST["id"]))
{
foreach($_POST["id"] as $pid)
{
$sql = "DELETE FROM products WHERE id = '".$pid."'";
mysqli_query($conn, $sql);
}
}
?>
the codes above are the PHP codes that I added for my checkbox function.
The data can be deleted successfully in the database but it won't be able to delete the data that display on the page without the hard refreshh
please help me resolve this problem. I could not find any problem in the browser console. Thanks in advance
Ok simple ajax/php test
1st: The ajax part
$.ajax({
url:'includes/delete-in-bulk.php',
method:'POST',
data:{id:id},
success:function(response){
console.log(response);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
You may need to check includes/delete-in-bulk.php this path it will be much easier for you to use the full url path http://mywebsite.com/includes/delete-in-bulk.php
2nd: in php
<?php
print_r($_POST['id']);
?>
Now you should see the ids printed out in the console
3rd: In php
<?php
$ids = $_POST['id'];
foreach($ids as $pid){
echo $pid;
}
?>
Now you should see the ids printed out in the console
4th: check the session.php path .. start locate it from delete-in-bulk.php file maybe its ../../session.php
5th: Add your database code and use
if(mysqli_query($conn, $sql)){
echo 'ok';
}
Now you should see the ok in the console
After all of this now everything is ok to do anything in the ajax success callback

How to loop through all the records in jquery datatable in php

I have JQUERY datatable in my PHP page in which I have one check box, I want to get the values of all the check boxes checked in that datatable with php code by using
implode(',',$_POST['accessflag']);
But it is showing the values only on the current page. I want to get the values of all checked check boxes in the datatable from all the pages of that particular table .anybody please help me to get this done.
my HTML code is
<div class="row control-container pt-2">
<div class="table-responsive col-md-12">
<div class="row">
<div class="col-md-12" style="text-align:center">
<label style="color:red">
<?php if (isset($_SESSION['SaveMsg'])) { echo $_SESSION['$SaveMsg'];unset($_SESSION['$SaveMsg']);}?>
</label>
</div>
</div>
<table id="moduletable" class="table table-sm table-bordered table-hover table-lightfont display">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GMA_ACCESS_FLAG"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","OPTIONS"); ?></th>
</tr>
</thead>
<tbody>
<?php
if(isset($_SESSION['$nextset'])){
$limit=$_SESSION['$nextset'];}
else{$limit=0;}
if ($_SESSION['$language']="E") {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_desc,gma_module_id,module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id LIMIT ".$limit.",50");
}
else {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_bldesc as grp_desc,gma_module_id,module_blname as module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id LIMIT ".$limit.",50");
}
foreach ($groupdata as $groupdatalist) {?>
<tr>
<td><?php echo $groupdatalist["grp_desc"];?></td>
<td><?php echo $groupdatalist["module_name"];?></td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<td style="text-align:right;width:10px;"><input type="checkbox" name="accessflag[]" id="accessflag"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php else:?>
<td style="text-align:right;width:10px;"><input type="checkbox" checked name="accessflag[]" id="accessflag" width="10px"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php endif;?>
<!--<td style="display:none;"><//?php echo $groupdatalist["gma_grp_id"];?></td>
<td style="display:none;"><//?php echo $groupdatalist["gma_module_id"];?></td>
<td style="display:none;"><input type="text" name="gmaid" id="gmaid" value="<//?php echo $groupdatalist["gma_id"];?>"></td>-->
<td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<a href="#" class="btn btn-light btn-sm pt-0 shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
<?php else:?>
<a href="group_action.php?gmagrpid=<?php echo $groupdatalist['gma_grp_id']?>&gmamoduleid=<?php echo $groupdatalist['gma_module_id']?>&page=MenuPermission&gmagrpdesc=<?php echo $groupdatalist['grp_desc']?>&gmamodulename=<?php echo $groupdatalist['module_name']?>" class="btn btn-light btn-sm pt-0 shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
<?php endif;?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" name="updmodaccess" formnovalidate class="btn nc btn-primary btn-rounded">
<i class="fa fa-save"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","SAVE"); ?>
</button>
</div>
</div>
</div>
</div>
PHP code on updmodaccess button is
if (isset($_POST['updmodaccess'])) {
$keytoupdate=implode(',',$_POST['accessflag']);
$table="group_module_access"; $data=array("gma_access_flag"=>"Y", "gma_upd_dt"=>GetDateTime($_SESSION['$TimeZone']), "gma_upd_uid"=>"{$_SESSION['$userid']}");
UpdateData($table,$data,"gma_id in (".$keytoupdate.")",$Message,$flg);
$data=array("gma_access_flag"=>"N", "gma_upd_dt"=>GetDateTime($_SESSION['$TimeZone']), "gma_upd_uid"=>"{$_SESSION['$userid']}");
UpdateData($table,$data,"gma_id not in (".$keytoupdate.")",$Message,$flag);
}
you can try the following code. I hope it helps.
you need to get these values using ajax and then need to send this value to php using an ajax.
$(document).ready(function(){
var data = new Object();
var table = $('#addUsersToAboTable').DataTable();
$('#addUsersToAboTable').on('change', ':checkbox', function () {
data[table.row($(this).parents('tr').get(0)).index()] = this.checked;
});
$('#getDataBtn').on('click',function(){
console.log(data);
});
});
Here you can see the demo script as well jQuery Datatables, How to get all selected checkboxes from EVERY page

form button worked before, now it doesn't anymore

<script>
$(document).ready(function() {
var panels = $('.user-infos');
var panelsButton = $('.dropdown-user');
panels.hide();
//Click dropdown
panelsButton.click(function() {
//get data-for attribute
var dataFor = $(this).attr('data-for');
var idFor = $(dataFor);
//current button
var currentButton = $(this);
idFor.slideToggle(400, function() {
//Completed slidetoggle
if(idFor.is(':visible'))
{
currentButton.html('<i class="glyphicon glyphicon-chevron-up text-muted"></i>');
}
else
{
currentButton.html('<i class="glyphicon glyphicon-chevron-down text-muted"></i>');
}
})
});
$('[data-toggle="tooltip"]').tooltip();
$('button').click(function(e) {
e.preventDefault();
});
});
</script>
<script>
function showMe(){
document.querySelector('#change').style.display = '';
document.querySelector('#keep').style.display = 'none'
document.querySelector('#change1').style.display = '';
document.querySelector('#keep1').style.display = 'none'
document.querySelector('#change2').style.display = '';
document.querySelector('#keep2').style.display = 'none'
document.querySelector('#change3').style.display = '';
document.querySelector('#keep3').style.display = 'none'
document.querySelector('#change4').style.display = '';
document.querySelector('#keep4').style.display = 'none'
document.querySelector('#change5').style.display = '';
document.querySelector('#keep5').style.display = 'none'
}
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#wrapper').dialog({
autoOpen: false,
title: 'Upload an image!'
});
$('#opener').click(function(e) {
e.preventDefault();
$('#wrapper').dialog('open');
});
});
</script>
</head>
<body id="top">
<!-- Header -->
<header id="header">
<div class="inner">
<img src="logo-small.png" alt="" />
<br></br>
<h1>Jasmine</h1>
</div>
</header>
<!-- Main -->
<div id="main">
<!-- One -->
<section id="one">
<div class="container">
Logout
<?php
if($_GET['a'])
{
echo '<p style= "color:red;"> Please select an appropriate image ';
}
?>
<div class="row">
<div class="col-md-5 toppad pull-left col-md-offset-3 ">
<br>
<br>
<!-- <p class=" text-info">May 05,2014,03:00 pm </p>-->
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $firstname . " ". $lastname; ?></h3>
</div>
<form method= "post" action= "edit.php">
<div class="panel-body">
<div class="row">
<div class="col-md-3 col-lg-3 " id= "show"> <img alt="User Pic" src= <?php echo "../profilepic/" .$path; ?> class="img-circle img-responsive">
<button class="btn btn-sm btn-info" id="opener"><i class="glyphicon glyphicon-edit"></i></button>
</div>
<div class=" col-md-9 col-lg-9 ">
<table class="table table-user-information">
<tbody>
<tr>
<td>First name:</td>
<td><span id= "keep"><?php echo $firstname;?></span><input id= "change" value= "<?php echo $firstname; ?>" style= "display:none;" name="name"></td>
</tr>
<tr>
<td>Last name:</td>
<td><span id= "keep5"><?php echo $lastname;?></span><input id= "change5" value= "<?php echo $lastname; ?>" style= "display:none;" name="lname"></td>
</tr>
<tr>
<td>Date of Birth</td>
<td><span id= "keep1"><?php echo $birthday; ?></span><input id= "change1" value= "<?php echo $birthday; ?>" style= "display:none;" name="bday"></td>
</tr>
<tr>
<tr>
<td>Gender</td>
<td><span id= "keep2"><?php echo $gender; ?></span><input id= "change2" value= "<?php echo $gender; ?>" style= "display:none;" name="gen"></td>
</tr>
<tr>
<td>Country</td>
<td><span id= "keep3">US</span><input id= "change3" value= "US" style= "display:none;" name="country"></td>
</tr>
<tr>
<td>Email</td>
<td><span id= "keep4"><?php echo $email; ?></span><input id= "change4" value= "<?php echo $email; ?>" style= "display:none;" name="mail"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="panel-footer">
<a data-original-title="Broadcast Message" data-toggle="tooltip" type="button" class="btn btn-sm btn-primary"><i class="glyphicon glyphicon-envelope"></i></a>
<span class="pull-right">
</i>
<button data-original-title="Save this user" data-toggle="tooltip" type="submit" class="btn btn-sm btn-success" id="edit"><i class="glyphicon glyphicon-saved"></i></button>
</span>
</div>
</form>
</div>
</div>
</div>
<div id="wrapper">
<form method="POST" action="getdata.php" enctype="multipart/form-data">
<input type="file" name="image">
<input id="images" type="submit" value="Upload">
</form>
</div>
</section>
I have this form, and as you can see it goes to edit.php when I click the save/submit button, it used to work, now it doesn't anymore I'm not sure why, can anyone tell me what I am missing? It stopped working when I added the other form that is at the button for "upload image", but I checked all my errors and there aren't any about the forms and they don't clash, can anyone see what the issue is, Im stuck on it.

cant upload file in mysql database using php codeigniter [duplicate]

This question already has answers here:
codeigniter upload file error
(2 answers)
Closed 8 years ago.
I want to upload a file in mysql database using php codeigniter. when I upload a file it don't show any error and file doesn't upload.and the value of column file_name in mysql shows as NULL.
Here is my view code :
<div class="box">
<div class="box-header"><span class="title"><?php echo get_phrase('diagnosis_report');?></span></div>
<div class="box-content">
<table cellpadding="0" cellspacing="0" border="0" class="table table-normal ">
<thead>
<tr>
<td><div>#</div></th>
<td><div><?php echo get_phrase('report_type');?></div></td>
<td><div><?php echo get_phrase('document_type');?></div></td>
<td><div><?php echo get_phrase('download');?></div></td>
<td><div><?php echo get_phrase('description');?></div></td>
<td><div><?php echo get_phrase('date');?></div></td>
<td><div><?php echo get_phrase('laboratorist');?></div></td>
<td><div><?php echo get_phrase('option');?></div></td>
</tr>
</thead>
<tbody>
<?php
$count = 1;
$diagnostic_reports = $this->db->get_where('diagnosis_report' , array('prescription_id' => $prescription_id))->result_array();
foreach($diagnostic_reports as $row2):?>
<tr>
<td><?php echo $count++;?></td>
<td><?php echo $row2['report_type'];?></td>
<td><?php echo $row2['document_type'];?></td>
<td style="text-align:center;">
<?php if($row2['document_type'] == 'image'):?>
<div id="thumbs">
<a href="<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>"
style="background-image:url(<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>)" title="<?php echo $row2['file_name'];?>">
</a></div>
<?php endif;?>
<a href="<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>" target="_blank"
class="btn btn-blue"> <i class="icon-download-alt"></i> <?php echo get_phrase('download');?></a>
</td>
<td><?php echo $row2['description'];?></td>
<td><?php echo date('d M,Y', $row2['timestamp']);?></td>
<td><?php echo $this->crud_model->get_type_name_by_id('laboratorist',$row2['laboratorist_id'],'name');?></td>
<td align="center">
<a href="<?php echo base_url();?>index.php?laboratorist/manage_prescription/delete_diagnosis_report/<?php echo $row2['diagnosis_report_id'];?>/<?php echo $prescription_id;?>" onclick="return confirm('delete?')"
rel="tooltip" data-placement="top" data-original-title="<?php echo get_phrase('delete');?>" class="btn btn-red">
<i class="icon-trash"></i>
</a>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</div>
<!------DIAGNOSTIC REPORT FOR THIS PRESCRIPTION---->
<!------ADD A DIAGNOSTIC REPORT TO THIS PRESCRIPTION-->
<div class="box">
<div class="box-header"><span class="title"><?php echo get_phrase('add_diagnosis_report');?></span></div>
<div class="box-content">
<?php echo form_open('laboratorist/manage_prescription/create_diagnosis_report' , array('class' => 'form-horizontal validatable'));?>
<div class="padded">
<div class="control-group">
<label class="control-label"><?php echo get_phrase('report_type');?></label>
<div class="controls">
<input type="text" name="report_type" /> <span class="label label-blue">report type can be x-ray, blood-test etc.</span>
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('document_type');?></label>
<div class="controls">
<select name="document_type" >
<option value="image"><?php echo get_phrase('image');?></option>
<option value="doc" ><?php echo get_phrase('doc');?></option>
<option value="pdf"><?php echo get_phrase('pdf');?></option>
<option value="excel"><?php echo get_phrase('excel');?></option>
<option value="other"><?php echo get_phrase('other');?></option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('upload_document');?></label>
<div class="controls">
<input type="file" name="userfile" />
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('description');?></label>
<div class="controls">
<textarea name="description" ></textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="hidden" name="prescription_id" value="<?php echo $prescription_id;?>" />
<button type="submit" class="btn btn-blue"><?php echo get_phrase('add_diagnosis_report');?></button>
</div>
</div>
</div>
</form>
</div>
</div>
and here is my code to upload file in database :
function manage_prescription($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('laboratorist_login') != 1)
redirect(base_url() . 'index.php?login', 'refresh');
if ($param1 == 'create_diagnosis_report') {
$data['report_type'] = $this->input->post('report_type');
$data['document_type'] = $this->input->post('document_type');
$data['prescription_id'] = $this->input->post('prescription_id');
$data['description'] = $this->input->post('description');
$data['timestamp'] = strtotime(date('Y-m-d') . ' ' . date('H:i:s'));
$data['laboratorist_id'] = $this->session->userdata('laboratorist_id');
move_uploaded_file($_FILES["userfile"]["tmp_name"] , "uploads/diagnosis_report/".$_FILES["userfile"]["name"]);
$data['file_name'] = $_FILES["userfile"]["name"];
$this->db->insert('diagnosis_report', $data);
$this->session->set_flashdata('flash_message', get_phrase('diagnosis_report_created'));
redirect(base_url() . 'index.php?laboratorist/manage_prescription/edit/' . $this->input->post('prescription_id'), 'refresh');
}
if ($param1 == 'delete_diagnosis_report') {
$this->db->where('diagnosis_report_id', $param2);
$this->db->delete('diagnosis_report');
$this->session->set_flashdata('flash_message', get_phrase('diagnosis_report_deleted'));
redirect(base_url() . 'index.php?laboratorist/manage_prescription/edit/' . $param3, 'refresh');
} else if ($param1 == 'edit') {
$page_data['edit_profile'] = $this->db->get_where('prescription', array(
'prescription_id' => $param2
))->result_array();
}
$page_data['page_name'] = 'manage_prescription';
$page_data['page_title'] = get_phrase('manage_prescription');
$page_data['prescriptions'] = $this->db->get('prescription')->result_array();
$this->load->view('index', $page_data);
}
You have to use form_open_multipart() not form_open() in your view file

Display specific row data in bootstrap modal with edit button click

I am new to programming and trying to implement bootstrap modal to display row data from a mysql table into the modal window.
I have tried the solution found on stackoverflow "Pull information from mysql table to bootstrap modal to edit" by link. But could not able to display the particular row with the $row['SFID'].
I can pull table data but when I click the edit button in front of any row it always show the last row id
and doesn't display the data in the input box on the modal to edit the data???.
Here I am till now, Please help me out.
<table class="table table-bordered" width="100%">
<thead>
<tr>
<th>SFID</th>
<th>Company</th>
<th>Product</th>
<th>Product Line</th>
<th>Dealer Class</th>
<th>Status</th>
</tr>
</thead>
<?php
$query = "SELECT * FROM tblcustomer";
$stmt = $db->prepare($query);
$stmt->execute();
foreach ($stmt as $row): ?>
<tr>
<?php $rowID = $row['SFID']; ?>
<td><?php echo $row['SFID']; ?></td>
<td><?php echo $row['CompanyName']; ?></td>
<td><?php echo $row['Product']; ?></td>
<td><?php echo $row['ProductLine']; ?></td>
<td><?php echo $row['DealerClass']; ?></td>
<td><?php echo $row['RequestStatus']; ?></td>
<td style="text-align: center">
<div class="btn-toolbar">
<div class="btn-group">
<a class="btn btn-danger" href="#delModal" data-toggle="modal"><i class="icon-trash icon-white"></i> Delete</a>
<?php echo "<a class='btn update' href='#editModal' data-sfid='".$row['SFID']."' role='button' data-toggle='modal'>Edit</a>"; ?>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>
<div id="editModal" class="modal hide fade in" style="display: none; ">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Edit Customer Details</h3>
</div>
<div>
<form class="contact">
<fieldset>
<div class="modal-body">
<?php echo $row['SFID']; ?>
<ul class="nav nav-list">
<li class="nav-header">SFID</li>
<li><input class="input-xlarge" type="text" name="mysfid" id="mysfid"></li>
<!--<li class="nav-header">Company</li>
<li><input class="input-xlarge" value=" " type="text" name="mycompany"></li>
<li class="nav-header">Dealer Class</li>
<li><input class="input-xlarge" value=" " type="text" name="mydealerclass"></li> -->
</ul>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-success" id="submit">Approved</button>
Close
</div>
</div>
<script>
$(document).ready(function(){
$('a.edit').click(function(){
var sfid = $(this).data('sfid');
var company = $(this).data('company');
var dealerclass = $(this).data('dealerclass');
$('#mysfid').val(sfid);
$('#mycompany').val(company);
$('#mydealerclass').val(dealerclass);
});
});
</script>
Thanks for your help.
<table class="table table-bordered" width="100%">
<thead>
<tr>
<th>SFID</th>
<th>Company</th>
<th>Product</th>
<th>Product Line</th>
<th>Dealer Class</th>
<th>Status</th>
</tr>
</thead>
<?php
$query = "SELECT * FROM tblcustomer";
$result = mysql_query($query);
$i=1;
while($row = mysql_fetch_assoc($result))
{
?>
<tr>
<?php $rowID = $row['SFID']; ?>
<td><?php echo $row['SFID']; ?></td>
<td><?php echo $row['CompanyName']; ?></td>
<td><?php echo $row['Product']; ?></td>
<td><?php echo $row['ProductLine']; ?></td>
<td><?php echo $row['DealerClass']; ?></td>
<td><?php echo $row['RequestStatus']; ?></td>
<td style="text-align: center">
<div class="btn-toolbar">
<div class="btn-group">
<a class="btn btn-danger" href="#delModal" data-toggle="modal"><i class="icon-trash icon-white"></i> Delete</a>
<a class="btn update" href="#editModal<?php echo$i?>" data-sfid='"<?php echo $row['SFID'];?>"' data-toggle="modal">Edit</a>
<!--Yor Edit Modal Goes Here-->
<div id="editModal<?php echo $i; ?>" class="modal hide fade in" role="dialog" ria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Edit Customer Details</h3>
</div>
<div>
<form class="contact">
<fieldset>
<div class="modal-body">
<?php echo $row['SFID']; ?>
<ul class="nav nav-list">
<li class="nav-header">SFID</li>
<li><input class="input-xlarge" type="text" name="mysfid" id="mysfid"></li>
<!--<li class="nav-header">Company</li>
<li><input class="input-xlarge" value=" " type="text" name="mycompany"></li>
<li class="nav-header">Dealer Class</li>
<li><input class="input-xlarge" value=" " type="text" name="mydealerclass"></li> -->
</ul>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-success" id="submit">Approved</button>
Close
</div>
</div>
</div>
</div>
</td>
</tr>
<?php $i++; } ?>
</table>
take $i = 1 above for loop and increament it in each iteration of for loop..so it will take each records
Your Form
<a class='btn update' href='#editModal<?php echo $i;?>' data-sfid='".$row['SFID']."' role='button' data-toggle='modal'>Edit</a>
Modal Window
<div id="editModal<?php echo $i;?>" class="modal hide fade in" style="display: none; ">
That's because you fill the edit modal with the $row data, which by then, is on the last item.
To get data for a specific row, you could create a javascript object/array and then fetch the data by making use of the data-rfid parameter in the "Edit" link. Or you can fetch the row with Ajax for example.

Categories