I have this code and I want to make the BIT column Color 1 by pressing the check button and I really can't handle the php. I need help, please!
There is the table and how I access each data from the SQL server, it shows fine but the button is not doing anything when I'm trying to _POST in php. I have been looking for an answer but I couldn't find anything.
<table class="table table-hover">
<thead class="thead-light">
<tr>
<th scope="col">Nr Expediente</th>
<th scope="col">Fecha</th>
<th scope="col">Tipo</th>
<th scope="col">Responsable</th>
<th scope="col">Proveedor</th>
<th scope="col">Observaciones</th>
<th scope="col">Hora</th>
<th scope="col">Check</th>
</tr>
</thead>
<tbody>
<?php
$query="SELECT dbo.Transportes.IdExpediente, dbo.Operaciones.IdTransporte, dbo.Operaciones.Id, dbo.Operaciones.Color, dbo.Operaciones.CreadoPor, dbo.Expedientes.Numero, dbo.Expedientes.ProveedorNombre, dbo.Operaciones.Fecha, dbo.Operaciones.Tipo, dbo.Operaciones.Hora, dbo.Operaciones.Instrucciones FROM dbo.Expedientes
INNER JOIN dbo.Transportes ON dbo.Expedientes.Id = dbo.Transportes.IdExpediente INNER JOIN dbo.Operaciones ON dbo.Operaciones.IdTransporte = dbo.Transportes.Id
WHERE convert(date, convert(varchar(30), dbo.Operaciones.Fecha), 101) = CONVERT (date, GETDATE()) AND dbo.Operaciones.Tipo = 0 ORDER BY dbo.Operaciones.Id DESC";
$res=sqlsrv_query($con,$query);
while ($row=sqlsrv_fetch_array($res)){
?>
<tr <?php if ($row['Color'] == 1) {
echo 'class="table-success"';
} else { echo 'class="table-warning"';} ?> ><td><?php echo $row['Numero']; ?></td>
<td><?php echo $row['Fecha']->format('d/m/Y'); ?></td>
<td><?php if ($row['Tipo'] == 1) {
echo "Descarga";
} else { echo "Carga";} ?></td>
<td><?php echo $row['CreadoPor']; ?></td>
<td><?php echo $row['ProveedorNombre']; ?></td>
<td><?php echo $row['Instrucciones']; ?></td>
<td><?php echo $row['Hora']; ?></td>
<td>
<form method="post">
<div class="btn-group">
<button type="button" name="Checking" class="btn btn-success">Check</button>
<input type="hidden" name="id" value="' .$row['Id']. '"/>
<input type="hidden" name="color" value="1"/>
<button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">In progress</a>
<a class="dropdown-item" href="#">Save for later</a>
<div class="dropdown-divider"></div>
<button type="butoon" name="Unchecking">Uncheck</a>
</div>
</div> </form></td></tr>
<?php
}
?>
</tr>
</tbody>
</table>
<?php if(isset($_POST['Checking'])){
$sql = "UPDATE dbo.Operaciones SET
Color = '1'
WHERE Id = {_POST['id']} ";
$result = sqlsrv_query($con,$sql) or die(sqlsrv_errors());
}
?>
change type="button" to type="submit"
and
change
$sql = "UPDATE dbo.Operaciones SET
Color = '1'
WHERE Id = ".$_POST['id'] ;
Related
I have a table that displays a list of tasks for a client. Each task has the ability to have multiple notes. Tasks and notes are kept in separate tables, but brought together in this table by a sub-query that does a group_concat to be able to show the many-to-one relationship between a task and the notes for that task. The problem is that lengthy notes do not show the full text. The field in the notes table contains the full text that is needed. It is a blob data type and the data length is 1191 bytes. My research tells me that doing this select with the group_concat makes the returning Note field over 1024 bytes, which is the limit. And indeed the 'group_concat_max_len' is set to 1024. I have been instructed by my boss that rather than increase the data limit, I should figure out how to work within the limit. Can anyone give me some suggestions on how to modify this select statement to allow for the one-to-many statement but not limit the data length?
<div class="portlet light bordered">
<div class="portlet-title">
<div class="col-md-8">
<div class="caption font-dark">
<i class="fa fa-tasks font-dark"></i>
<span class="caption-subject bold uppercase">Task List</span>
</div>
</div>
</div>
<div class="portlet-body">
<table class="table table-striped table-bordered table-hover dt-responsive"
width="100%" id="sample_3" cellspacing="0" width="100%">
<thead>
<tr>
<th class="all">Task Step</th>
<th class="all">Envr</th>
<th class="all">Task Name</th>
<th class="all">Task Description</th>
<th class="none">Notes:</th>
<th class="all">Due Date</th>
<th class="all">Current Status</th>
</tr>
</thead>
<tbody>
<?php
include "../includes/DBConn.php";
$sql = "SELECT ID, FID , TaskCategory, Environment, TaskName, TaskDescription,
CreateDate, Cast(date_format(DueDate, \"%m-%d-%Y\") as char) as DueDate,
CompletedDate, CompletedBy, CurrStatus,
(SELECT GROUP_CONCAT(Cast(date_format(DATE(CreateDate),\"%m-%d-%Y\") as
char), \" <strong>\" , Cast(TIME(CreateDate) as char) , \"</strong> : \" ,
Notes ORDER BY CreateDate ASC SEPARATOR '<br>')
FROM arc.notes B where A.id = B.taskid
) as Notes
FROM arc.task A
WHERE FID = '$FID'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$TaskID = $row['ID'];
$TaskStep = $row['TaskCategory'] . $row['ID'];
$Environment = $row['Environment'];
$TaskName = $row['TaskName'];
$TaskDescription = $row['TaskDescription'];
$Notes = $row['Notes'];
$DueDate = $row['DueDate'];
$CompleteDate = $row['CompletedDate'];
$CurrStatus = $row['CurrStatus'];
?>
<tr>
<td><?php echo "$TaskStep "; if(!empty($Notes)) { echo " <i class=\"fa fa-
sticky-note\"></i>";} ?></td>
<td><?php echo "$Environment"; ?></td>
<td><?php echo "$TaskName"; ?></td>
<td><?php echo "$TaskDescription"; ?></td>
<td><a class="btn btn-circle btn-xs red-mint" data-toggle="modal"
href="#newNote<?php echo$TaskID;?>"><i class="fa fa-plus"></i>Add Note
</a>
<br>
<?php echo $Notes; ?>
</td>
<td><?php echo "$DueDate"; ?></td>
<td><?php switch ($CurrStatus) {
case (0): echo "<strong><a class=\"btn btn-xs btn-primary btn-
block\" data-toggle=\"modal\" href=\"#StatusChange" .
$TaskStep . "\">AWAITING ACTION</strong>";
break;
case (1): echo "<strong><a class=\"btn btn-xs btn-success btn-
block\" data-toggle=\"modal\" href=\"#StatusChange" .
$TaskStep . "\">IN PROGRESS</strong>";
break;
case (2): echo "<strong><a class=\"btn btn-xs grey-gallery btn-
block\" data-toggle=\"modal\" href=\"#StatusChange" .
$TaskStep . "\">COMPLETED</strong>";
break;
default: echo "No Status";
}
?>
</td>
</tbody>
</div>
</div>
</div>
I'm trying to generate a table of all user accounts and then have buttons next to each user to either delete or change the account level of the user (admin or not admin). What would be the best way to go about this?
Here's my code:
<?php
$query = mysql_query("SELECT user_name,user_id,user_email,user_level
FROM users
ORDER BY user_name ASC");
echo '<table class="table table-hover">
<thead class="thead-default">
<tr>
<th>Username</th>
<th>User ID</th>
<th>Email</th>
<th>Level</th>
<th>Options</th>
</tr>
</thead>';
while($row = mysql_fetch_array($query)){
echo '<tbody>
<tr>
<td class="col-3">' .$row['user_name'].'</td>
<td class="col-3">' .$row['user_id'].'</td>
<td class="col-3">' .$row['user_email'].'</td>
<td class="col-3">' .$row['user_level'].'</td>
<td class="col-3"><a class="btn btn-success" href="#" data-toggle="tooltip" title="Edit"><span class="glyphicon glyphicon-pencil"></span></a>
<a class="btn btn-success" href="#" data-toggle="tooltip" title="Promote"><span class="glyphicon glyphicon-arrow-up"></span></a>
<a class="btn btn-danger" href="#"><span class="glyphicon glyphicon-arrow-down" data-toggle="tooltip" title="Demote"></span></a>
<a class="btn btn-danger" href="delete.php" data-toggle="tooltip" title="Delete"><span class="glyphicon glyphicon-trash"></span></a>
</td>
</tr>
</tbody>';
}
echo '</table>'; ?>
Any help would be appreciated :)
Edit: The admin/standard user is set via user_level with 0 being standard user and 1 being admin
edit 2: Added code
<?php
include 'connect.php';
include 'header.php';
mysql_query("UPDATE users SET user_level='1' WHERE user_id='".$_GET['user_id']."'");
die("User promoted to admin.");
include 'footer.php';
?>
Getting no luck with it, will try to add if statements for feedback on if database row changes
This here is example of code, because your questions lack some details, so i am sharing my code.
<table>
<tr>
<th>User Email </th>
<th>Date & Time </th>
<th>Complain Number</th>
<th>Complain Type</th>
<th>Description</th>
<th>Status</th>
</tr>
<?php
$ccount =1;
$email= $_SESSION["email"];
$query = mysqli_query($con,"Select * from new_complain where new_email =
'$email'");
while($rows = $query->fetch_assoc())
{
?>
<tr>
<input type="hidden" name="<?php echo 'sstd' . $ccount ; ?>" value="<?php
echo $rows['complain_type']; ?>" placeholder="Student Name" />
<td><?php echo $_SESSION["email"]; ?></td>
<td><?php echo $rows['complain_date']; ?></td>
<td><?php echo $rows['new_id']; ?></td>
<td><?php echo $rows['complain_type']; ?></td>
<td><?php echo $rows['new_complain']; ?></td>
<td><?php echo $rows['comlain_status']; ?></td>
</tr>
<?php
$ccount++;
} ?>
</table>
Without full details, it would be something like this:
<a class="btn btn-success" href="promote.php?id='.$row['user_id'].'" data-toggle="tooltip" title="Promote"><span class="glyphicon glyphicon-arrow-up"></span></a>
<a class="btn btn-danger" href="demote.php?id='.$row['user_id'].'"><span class="glyphicon glyphicon-arrow-down" data-toggle="tooltip" title="Demote"></span></a>
Then you need a promote.php in the same directory as this file, which would look like this:
<?php
mysql_query("UPDATE users SET user_level='1' WHERE user_id='".$_GET['user_id']."'");
die("User promoted to admin user.");
And a demote.php like so:
<?php
mysql_query("UPDATE users SET user_level='0' WHERE user_id='".$_GET['user_id']."'");
die("User demoted to standard user.");
I have a page where users can view the leave applications they submitted and they can also cancel the application, here's what it looks like:
I wanted to get rid of the cancel button after it was cancelled or after it was clicked. So I added a remove button script in the execution code. Apparently, it was wrong. Everything worked fine until I added the script in the execution code.
Here's my form:
HTML+PHP
<div class="container">
<div class="page-header">
<h3>My Leaves</h3>
<div class="table-responsive">
<table class="table">
<tr>
<th>Employee Name</th>
<th>Phone</th>
<th>Email</th>
<th>From</th>
<th>To</th>
<th>Reason</th>
<th>Type</th>
<th>Status</th>
</tr>
<?php
include ('database.php');
$result = $database->prepare ("SELECT leaves.* FROM leaves INNER JOIN employee ON employee.id = leaves.user_id WHERE employee.username = '".$_SESSION["VALID_USER_ID"]."'");
$result ->execute();
for ($count=0; $row_message = $result ->fetch(); $count++){
?>
<tr>
<td><?php echo $row_message['firstname']." " .$row_message['lastname']; ?></td>
<td><?php echo $row_message['phone']; ?></td>
<td><?php echo $row_message['email']; ?></td>
<td><?php echo $row_message['fromdate']; ?></td>
<td><?php echo $row_message['todate']; ?></td>
<td><?php echo $row_message['reason']; ?></td>
<td><?php echo $row_message['type']; ?></td>
<td><?php echo $row_message['status']; ?></td>
<td>
<form method="post" action="update-leave-status-emp.php">
<input type="hidden" name="leaveno" value="<?php echo $row_message['leaveno']; ?>" />
<input type="submit" value="Cancelled" class="removebtn" name="cancelled"></input>
</form>
</td>
</tr>
<?php }?>
</table>
<a href="employee_panel.php">
<button type="button" class="btn btn-primary"><i class="glyphicon glyphicon-arrow-left"></i> Back</button>
</a>
</div>
</div>
</div>
Execution Code:
<?php
if(isset($_POST['cancelled'])){
$msg = "Cancelled";
$status=$_POST['cancelled'];
echo "<script>
$(document).ready(function(){
$(".removebtn").click(function(){
$(this).remove();
});
});
</script>";
}
$leaveno=$_POST['leaveno'];
$con = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con, 'companydb');
$sql = "UPDATE leaves SET status = '$status' WHERE leaveno = '$leaveno'";
if(mysqli_query($con, $sql))header("refresh:1; url=view-leave-emp.php?msg=$msg");
else var_dump(mysqli_error($con));
?>
PS: I know my codes are vulnerable to injections, I will change it eventually, for now, I have to figure this out.
Enclosed cancelled button in an if statement that if the record is marked cancelled the button won't be shown anymore.
You can try this updated code:
<div class="container">
<div class="page-header">
<h3>My Leaves</h3>
<div class="table-responsive">
<table class="table">
<tr>
<th>Employee Name</th>
<th>Phone</th>
<th>Email</th>
<th>From</th>
<th>To</th>
<th>Reason</th>
<th>Type</th>
<th>Status</th>
</tr>
<?php
include ('database.php');
$result = $database->prepare ("SELECT leaves.* FROM leaves INNER JOIN employee ON employee.id = leaves.user_id WHERE employee.username = '".$_SESSION["VALID_USER_ID"]."'");
$result ->execute();
for ($count=0; $row_message = $result ->fetch(); $count++){
?>
<tr>
<td><?php echo $row_message['firstname']." " .$row_message['lastname']; ?></td>
<td><?php echo $row_message['phone']; ?></td>
<td><?php echo $row_message['email']; ?></td>
<td><?php echo $row_message['fromdate']; ?></td>
<td><?php echo $row_message['todate']; ?></td>
<td><?php echo $row_message['reason']; ?></td>
<td><?php echo $row_message['type']; ?></td>
<td><?php echo $row_message['status']; ?></td>
<td>
<form method="post" action="update-leave-status-emp.php">
<input type="hidden" name="leaveno" value="<?php echo $row_message['leaveno']; ?>" />
<?php if( $row_message['status'] != "Cancelled" ) {
<input type="submit" value="Cancelled" class="removebtn" name="cancelled"></input>
<?php } ?>
</form>
</td>
</tr>
<?php }?>
</table>
<a href="employee_panel.php">
<button type="button" class="btn btn-primary"><i class="glyphicon glyphicon-arrow-left"></i> Back</button>
</a>
</div>
</div>
</div>
I want to show a hidden div when I mouse over a link on my table cell. The event only fires up on the first row. This is what i did:
$(document).ready(function(){
$("#show_div").mouseover(function() {
$("#hello").css('visibility', 'visible');
});
$("#hello").mouseover(function() {
$("#hello").css('visibility', 'visible');
});
$("#hello").mouseout(function() {
$("#hello").css('visibility', 'hidden');
});
});
<form action="" method="post">
<table class="table table-bordered table-hover">
<div id="bulkOptionContainer" class="col-xs-4">
<select class="form-control" name="bulk_options" id="">
<option value="">Select Option</option>
<option value="publish">Publish</option>
<option value="draft">Draft</option>
<option value="delete">Delete</option>
</select>
</div>
<div class="col-xs-4">
<input class="btn btn-success" type="submit" name="submit" value="Apply"/>
<a class="btn btn-primary" href="posts.php?source=add_post">Add New</a>
</div>
<thead>
<tr>
<th><input type="checkbox" name="checkbox[]" id="selectAllCheckBoxes"></th>
<th>Id</th>
<th>Author</th>
<th scope="col">Title</th>
<th>Category</th>
<th>Status</th>
<th>Image</th>
<th>Tags</th>
<th>Comments</th>
<th>Date</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php $query = "SELECT * FROM post ORDER BY post_id DESC";
$result_set = mysqli_query($link, $query);
confirm_query($result_set);
while ($row = mysqli_fetch_assoc($result_set)):?>
<tr>
<td><label><input type="checkbox" class="checkBoxes" name="checkBoxArray[]"
value="<?php echo $row['post_id']; ?>"></label></td>
<td><?php echo $row['post_id'] ?></td>
<td><?php echo $row['post_author'] ?></td>
<td width="100%">
<!-- link to over-->
<a id="show_div"
href="../post.php?p_id=<?php echo $row['post_id'] ?>"><?php echo $row['post_title'] ?></a>
<!-- div to become visible on hover-->
<div id="hello" style="visibility:hidden;">
<p>post</p>
</div>
</td>
<td><?php echo sel_cat_byId($row['post_category_id']) ?></td>
<td><?php echo $row['post_status'] ?></td>
<td><img width="100" class="img-responsive" src="../images/<?php echo $row['post_image'] ?>"></td>
<td><?php echo $row['post_tag'] ?></td>
<td><?php echo $row['post_comment_count']; ?></td>
<td><?php echo $row['post_date'] ?></td>
<td><a class="btn btn-danger" href="posts.php?delete=<?php echo $row['post_id']; ?> "
onclick="alert('Are You Sure?')">Delete</a></td>
</td>
<td><a class="btn btn-success" href="posts.php?source=edit_post&edit=<?php echo $row['post_id']; ?>">Edit</a>
</td>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</form>
****the event only fires up on the first row.
Thanks
First replace your id with class and then try this
$(".show_div").mouseover(function() {
$(this).next(".hello").css('visibility', 'visible');
});
$(".show_div").mouseout(function() {
$(this).next(".hello").css('visibility', 'hidden');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<a class="show_div"
href="#">abc</a>
<!-- div to become visible on hover-->
<div class="hello" style="visibility:hidden;">
<p>post</p>
</div>
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>