//a table to display file from the database
<thead class="thead-inverse">
<tr>
<th>Description </th>
<th>Category</th>
<th>Upload By</th>
<th>Date</th>
<th></th>
</tr>
<thead>
<tbody class="sc">
<?php
// fetch the records from db
while ($row = mysql_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $row['fdesc']; ?></td> //filename
<td><?php echo $row['category']; ?></td>
<td><?php echo $row['username']; ?></td> //user who have upload the file
<td><?php echo $row['fdatein']; ?></td>
//the download button
<td><a href="" ><button type="button" class="btn btn-unique active" data-toggle="tooltip" data-placement="right" title="Download"><i class="fa fa-download"></i> // get the specific to download
</button></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
you can add the id in the the link url like so:
<a href="d1.php?fileId=<?php echo $row['fileID']; ?>" >
then in d1.php the id will be in the variable $_GET['fileID']
Related
I want to display all of my images from the database but it seems like it's not properly displayed. I've tried many times but still not well displayed. Everything is displayed except the image.
This is the code.
<?php
include("include/connection.php");
$query = "SELECT * FROM cat";
$result = mysqli_query($conn, $query);
?>
This is the table
<form action="add_cat.php"><div align="right"><button class="btn btn-success mb-2">Add New Cat</button></div></form>
<table class="table border border-dark" width="50%" cellpadding="5" cellspacing="5">
<thead class="thead-secondary">
<tr>
<th scope="col">Num</th>
<th scope="col">Cat ID</th>
<th scope="col">Picture</th>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Gender</th>
<th scope="col">Description</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<!-- fetched data from cat table -->
<?php
$num =1;
while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<th scope="row"></th>
<td><?php echo $num; ?></td>
<td><?php echo $row['id_cat']; ?></td>
<td> <?php echo '<img src="data:img/cat;base64,' .base64_encode($row['picture']).'" style="width:100px; height:100px;">'; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['age']; ?></td>
<td><?php echo $row['gender']; ?></td>
<td><?php echo $row['description']; ?></td>
<td>
<button class="btn btn-primary">Edit</button>
<button class="btn btn-danger">Delete</button>
</td>
</tr>
<?php $num++;
} ?>
</tbody>
</table>
It might be because the mime type for the img src attribute isn't valid.
It should be something like image/jpeg, image/png, image/webp etc, depending on the format of the image stored in your database.
<tr>
...
<td><?= $row['id_cat'] ?></td>
<td><img src="data:image/png;base64, <?= base64_encode($row['picture']) ?>" style="width:100px; height:100px;"></td>
<td><?= $row['name'] ?></td>
...
</tr>
Note: The <?= $content ?> syntax is shorthand for <?php echo $content; ?> and should be supported by default if you're using PHP 5.4 or newer (You should be at least using 7.4).
<table class="table admin-table list-table nurserytwo-table">
<thead>
<tr>
<td>ID</td>
<td>Name</td>
<td>Code</td>
<td>Active</td>
<td>Edit</td>
</tr>
</thead>
<tbody>
<?php foreach($nurseries->result() as $nursery) { ?>
<tr>
<td><?php echo $nursery->id; ?></td>
<td><?php echo $nursery->name; ?></td>
<td><?php echo $nursery->code; ?></td>
<td><?php echo set_bool($nursery->active); ?></td>
<td><span class="glyphicon glyphicon-edit"></span> <?php echo
anchor('admin/nurseries/edit_nursery/'.$nursery->id, 'Edit', 'class="edit-
link"'); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
This is my current table code and I have had a good look around to see if I can work out how to do this but I am really new to php and can't seem to get my head around it. I need to add a delete button after the edit one and I know I could do this via a delete.php but no idea where to start. Any help would be much appreciated.
UPDATED:
This is what I have currently:
}elseif( $action == "delete_nursery_course" ){
if($id) {
$q = $this->db->where('id', $id)->delete('nursery_courses');
if($this->db->affected_rows() > 0) {
if($this->input->is_ajax_request()) {
$this->output->enable_profiler(FALSE);
echo "SUCCESS"; die();
}else{
set_flash_message('Nursery deleted successfully.',
'success');
}
}else{
if($this->input->is_ajax_request()) {
$this->output->enable_profiler(FALSE);
echo "Something went wrong. Please try again."; die();
}else{
set_flash_message('Something went wrong. Please try
again.', 'error');
}
}
And here is the html:
<table class="table admin-table list-table nurseryone-table">
<thead>
<tr>
<td>ID</td>
<td>Name</td>
<td>Colour</td>
<td>Active</td>
<td>Edit</td>
<td>Delete</td>
</tr>
</thead>
<tbody>
<?php foreach($nursery_courses->result() as $nursery_course) { ?>
<tr>
<td><?php echo $nursery_course->id; ?></td>
<td><?php echo $nursery_course->name; ?></td>
<td><div style="background:<?php echo $nursery_course->colour; ?>"
class="course-colour"></div></td>
<td><?php echo set_bool($nursery_course->active); ?></td>
<td><span class="glyphicon glyphicon-edit"></span> <?php echo
anchor('admin/nurseries/edit_nursery_course/'.$nursery_course->id, Edit', 'class="edit-link"'); ?></td>
<td>
<span class="glyphicon glyphicon-trash"></span> <?php echo
anchor('admin/nurseries/delete_nursery_course/'.$nursery_course->id,
'delete', 'class="delete-link"'); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
You could use only html and javascript with jquery to use ajax requests to make an edit and delete button.
HTML:
<td class="text-right">
<a class="edit btn btn-sm btn-default" href="javascript:;">
<i class="icon-note"></i>
</a>
<a class="delete btn btn-sm btn-danger" href="javascript:;">
<i class="icons-office-52"></i>
</a>
</td>
And in your javascript file you have to define the onclick events for this a buttons.
Here's a Plunker example with html and javascript code:
Editable Table
Also you could use jquery DataTables to make it easier and better.
Hope its help you.
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"); ?>
I am workin on PHP codeigniter
See this attached image, here i need to get values of selected checkboxes and save in a database table by clicking on the button called CONFIRM
My view Code:
<?php foreach($studentlist as $llist){
echo form_open("trusts/MoveData?id=".$llist['id']); }?>
<button name="submit" type="submit" value="<?php echo #$studentlist1->id; ?>" class="btn btn-success btn-flat pull-right marginBot10px"><i class="icon_set_1_icon-76"></i> CONFIRM </button>
<?php echo form_close(); ?>
<table class="table table-bordered" id="employee_grid">
<thead>
<tr>
<!--<th><input type="checkbox" id="select_all"></th>-->
<th>Select</th>
<th>Student Name</th>
<th>Gender</th>
<th>Email</th>
<th>Phone</th>
<th>Program Id</th>
<th>Program Name</th>
</tr>
</thead>
<tbody>
<?php
$i=1;
foreach($studentlist as $llist){
?>
<tr id="<?php echo $llist["id"]; ?>">
<td><input type="checkbox" name="ids[]" value="<?php echo $llist['id']; ?>"> </td>
<td><?php echo $llist['Name']; ?></td>
<td><?php echo $llist['Gender']; ?></td>
<td><?php echo $llist['Email']; ?></td>
<td><?php echo $llist['Phone']; ?></td>
<td><?php echo $llist['ProgramId']; ?></td>
<td><?php echo $llist['ProgramName']; ?></td>
<!-- <td></td>-->
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
How get selected checkbox values of this view in my controller?
When the form is submitted you an get the selected checkbox values like:
$selected = $this->input->post('ids');
here $selected is an array, so use foreach() to get its values.
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>