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).
Related
I create a table that contain of cat information. In that cat information, there are picture, name, age, gender, and description that I have to display in the table. The problem is, only the picture in the first row of the table displayed, while the rest are not displayed. The name, age, gender and description have no problem in displaying the data in the table. I have to display 10 cats information in the table.
Here is the code
<?php
include("include/connection.php");
$query = "SELECT * FROM cat";
$result = mysqli_query($conn, $query);
?>
<form action="add_cat.php"><div align="right"><button class="btn btn-success mb-2">Add New Cat</button></div></form>
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<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>
<td><?php echo $num; ?></td>
<td><?php echo $row['id_cat']; ?></td>
<td><?php echo "<img src= '", $row['picture'] ,"' width='175' height='100' />" ?> </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>
</div>
</form>
You have a typo in your syntax. Periods concatenate strings in PHP. It should be:
<?php echo "<img src= '". $row['picture'] ."' width='175' height='100' />" ?>
I tried to highlight records whose certain columns have some values other than NULL. I'm using dataTable plugin.
<table class="table table-striped table-hover" id="checkin-checkout-record-table">
<thead>
<tr>
<th>Employee Name</th>
<th>Check-in-date</th>
<th>Check-in-time</th>
<th>Check-out-date</th>
<th>Check-out-time</th>
<th class="col-lg-2">Late Check-in Remarks</th>
<th class="col-lg-2">Early Check-out Remarks</th>
</tr>
</thead>
<tbody>
<?php
foreach ($checkinCheckoutList as $member): ?>
<tr <?php
if(isset($member['early_checkout_remarks']) ||isset($member['delayed_checkin_remarks']))
{?>
style="background-color:red;"
<?php } ?> >
<td><?php echo $member['fullname'] ?></td>
<td> <?php echo $member['checkin_date']; ?></td>
<td> <?php echo $member['checkin_time']; ?></td>
<td><?php echo $member['checkout_date']; ?></td>
<td><?php echo $member['checkout_time']; ?></td>
<td><?php echo $member['delayed_checkin_remarks']; ?></td>
<td><?php echo $member['early_checkout_remarks']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
But the result is not as expected. Some records are not highlighted. This works well with other normal table. Please help.
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 have a table with multiple columns (index.php). One column is a checkbox. Whenever the checkbox is checked, it displays another row where you can select a quantity. You can then hit a button called "Add to Order" and it will take you to a confirmation page (index-order.php) where I want it to display each row along with all of the data in that specified row that has the checkbox checked. Currently, I am getting no errors in my console, but no data is being displayed at all.
What do I need to change to make this happen? Here is what I have so far.
Index.php code:
<form name="form1" method="POST" action="index-order.php">
<section id="addToOrder">
<button type="submit" class="order" id="order" name="order" value="AddToOrder">Add to Order</button>
</section>
<br>
<div id="my-div2" class="ui-widget">
<div class="ui-widget">
<table id="merchTable" cellspacing="5" class="sortable">
<thead>
<tr class="ui-widget-header">
<th class="sorttable_nosort"></th>
<th class="sorttable_nosort">Loc</th>
<th class="merchRow">Report Code</th>
<th class="merchRow">SKU</th>
<th class="merchRow">Special ID</th>
<th class="merchRow">Description</th>
<th class="merchRow">Quantity</th>
<th class="sorttable_nosort">Unit</th>
<th style="display: none;" class="num">Quantity #</th>
</tr>
</thead>
<tbody>
<?php foreach ($dbh->query($query) as $row) {?>
<tr>
<td class="ui-widget-content"><input type="checkbox" class="check" name="check"></td>
<td name="rows[0][0][loc]" class="loc ui-widget-content" id="loc-<?php echo intval ($row['Loc'])?>"><?php echo $row['Loc'];?></td>
<td name="rows[0][0][rp-code]" class="rp-code ui-widget-content" align="center" id="rp-code-<?php echo intval ($row['Rp-Code'])?>"><?php echo $row['Rp-Code'];?></td>
<td name="rows[0][0][sku]" class="sku ui-widget-content" id="sku-<?php echo intval ($row['SKU'])?>"><?php echo $row['SKU'];?></td>
<td name="rows[0][0][special-id]" class="special-id ui-widget-content" align="center" id="special-id-<?php echo intval ($row['Special-ID'])?>"><?php echo $row['Special-ID'];?></td>
<td name="rows[0][0][description]" class="description ui-widget-content" id="description-<?php echo intval ($row['Description'])?>"><?php echo $row['Description'];?></td>
<td name="rows[0][0][quantity]" class="quantity ui-widget-content" data-quantity="<?php echo $row['Quantity'] ?>" align="center" id="quantity-<?php echo intval ($row['Quantity'])?>"><?php echo $row['Quantity'];?></td>
<td name="rows[0][0][unit]" class="unit ui-widget-content" id="unit-<?php echo intval ($row['Unit'])?>"><?php echo $row['Unit'];?></td>
<td name="rows[0][0][quant]" style="display: none;" class="quantity_num ui-widget-content"><input type="textbox" style="width: 100px;" class="spinner" name="value" id="test"></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</form>
Index-order.php:
<?php if(isset($_POST['rows'])): ?>
<table cellspacing="20">
<tr align="center">
<th>Loc</th>
<th>Report Code</th>
<th>SKU</th>
<th>Special ID</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit</th>
<th>Quantity #</th>
</tr>
<?php
foreach($_POST['rows'][0] as $row):
?>
<tr align="center">
<td><?php echo $row['loc']; ?></td>
<td><?php echo $row['rp-code']; ?></td>
<td><?php echo $row['sku']; ?></td>
<td><?php echo $row['special-id']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quant']; ?></td>
</tr>
<?php
endforeach;
?>
</table>
I am okay with the precedent answer, I never heard about this kind of method with PHP and it doesn't seems to be the right solution. Anyway, the following post would maybe help you : How to get value from td's via $_POST.
You cannot transfer datas through POST by using td ; but an alternative would be to use the "hidden" type of forms element :
<form action="script.php" method="post">
<td class=".."><input type="hidden" name="td1" value="...">value</td>
...
</form>
In PHP, you'll grab the data with the $_POST array and the td1 name :
<?php var_dump($_POST); ?>
Itwould in my opinion be the easier way to get what you want in a proper way ; the link I gave upper is also talking about DOMDocument, but it looks more complex to manage with.
//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']