Not able to display image from database on webpage - php

I am not able to display my full image on my webpage from database
my codemy image is goint to database
$con= mysqli_connect("localhost", "root", "", "project");
if(!$con)
{
die('not connected');
}
$result= mysqli_query($con, "SELECT addplace, stayamount, foodamount, airlinesamount, noofdays,noofnights,
SUM(stayamount + foodamount + airlinesamount) AS totalamount,choose
FROM adddetails GROUP BY packageid");
?>
<div class="container">
<CENTER><h2>view packages</h2>
</CENTER>
<table class="table table-bordered">
<th>place</th>
<th>stay cost</th>
<th>food cost</th>
<th>flight cost</th>
<th>no of days</th>
<th>no of nights</th>
<th>total amount</th>
<th>image</th>
<?php
while($row =mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['addplace']; ?></td>
<td><?php echo $row['stayamount']; ?></td>
<td><?php echo $row['foodamount'] ;?></td>
<td><?php echo $row['airlinesamount'] ;?></td>
<td><?php echo $row['noofdays'] ;?></td>
<td><?php echo $row['noofnights'] ;?></td>
<td><?php echo $row['totalamount'] ;?></td>
<td><?php echo '<img src=data:image/jpeg;base64,'.base64_encode( $row['choose'] ).'>'; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
please rewrite my code and i want my image of 150*150 size to be fitted on my web page in my table

try using this.
<td><img src='".$row['choose']."'/></td>";

Related

Php automatic time countdown(timer) as soon as a record is inserted

I have a table for saving details including logging time.Just as soon as a new record is inserted I want the column 'Countdown' to start an automatic time countdown from 30min until it gets to zero(0).How do I go about it?Thanks.
Here is the table php code
`<?php $results = mysqli_query($db, "SELECT
Vehicle_name,Vehicle_make,Vehicle_color,Number_plate,Date,Time FROM
vehicle"); ?>
<div class="table">
<table>
<thead>
<tr>
<th>Vehicle name</th>
<th>Vehicle make</th>
<th>Vehicle color</th>
<th>Reg Number</th>
<th>Date</th>
<th>Time</th>
<th>Countdown</th>
<th colspan="4">Action</th>
</tr>
</thead>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row['Vehicle_name']; ?></td>
<td><?php echo $row['Vehicle_make']; ?></td>
<td><?php echo $row['Vehicle_color']; ?></td>
<td><?php echo $row['Number_plate']; ?></td>
<td><?php echo $row['Date']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td>
<a href="php_code.php?del=<?php echo $row['Number_plate']; ?>"
class="del_btn">Delete</a>
</td>
</tr>
<?php } ?>
`

Display php data in a html table using while loop

Each time i echo out information from the database using while loop, the first results are displayed in only one row while the rest of the results are printed outside the table as raw text.
<table class="table table-striped">
<thead>
<tr class="bg-info">
<th>Id</th>
<th>Customer</th>
<th>Order</th>
<th>Title</th>
<th>Quantity</th>
<th>Total</th>
<th>Paid</th>
<th>Created Time</th>
<th>Updated Time</th>
<th>Update Order</th>
<th>Delete Order</th>
</tr>
</thead>
<tbody>
<?php
if($sql->num_rows > 0){
while($data = $sql->fetch_array()):
?>
<tr>
<td><?php echo $database->escape_value($data['custom_id']); ?></td>
<td><?php echo $database->escape_value($data['order_id']); ?></td>
<td><?php echo $database->escape_value($data['title']); ?></td>
<td><?php echo $database->escape_value($data['quantity']); ?></td>
<td><?php echo $database->escape_value($data['total']); ?></td>
<td><?php echo $database->escape_value($data['paid']); ?></td>
<td><?php echo $database->escape_value($data['created_at']); ?></td>
<td><?php echo $database->escape_value($data['updated_at']); ?></td>
<td>Update Order</td>
<td>Delete</td>
</tr>
</tbody>
</table>
<?php endwhile; }else
echo "<div class='btn bg-danger'>search not found</div>";
?>
Guys,only the first result is displayed proparly in the table, i want all the data display inside the table.
You are closing the table inside the loop. It's important that you keep the row only in the while.
Then be careful to close all brackets correctly.
<thead>
<tr class="bg-info">
<th>Id</th>
<th>Customer</th>
<th>Order</th>
<th>Title</th>
<th>Quantity</th>
<th>Total</th>
<th>Paid</th>
<th>Created Time</th>
<th>Updated Time</th>
<th>Update Order</th>
<th>Delete Order</th>
</tr>
</thead>
<tbody>
<?php
if($sql->num_rows > 0){
while($data = $sql->fetch_array()){
?>
<tr>
<td><?php echo $database->escape_value($data['custom_id']); ?></td>
<td><?php echo $database->escape_value($data['order_id']); ?></td>
<td><?php echo $database->escape_value($data['title']); ?></td>
<td><?php echo $database->escape_value($data['quantity']); ?></td>
<td><?php echo $database->escape_value($data['total']); ?></td>
<td><?php echo $database->escape_value($data['paid']); ?></td>
<td><?php echo $database->escape_value($data['created_at']); ?></td>
<td><?php echo $database->escape_value($data['updated_at']); ?></td>
<td>Update Order</td>
<td>Delete</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
if($sql->num_rows == 0){
echo "<div class='btn bg-danger'>search not found</div>";
}
?>

adding inline CSS in datatable row on condition not working

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.

sql query not working in my webpage

I wrote a MySQL query in my PHP code to join two tables, but I don't want all the columns in the result
My place details table:
My registration table:
My Code
<?php
$con= mysqli_connect("localhost", "root", "", "project");
if(!$con)
{
die('not connected');
}
$result= mysqli_query($con, "SELECT placedetails.name,placedetails.doj,placedetails.total,placedetails.stay,placedetails.food,placedetails.travel,registration.username
FROM placedetails inner join registration on placedetails.id=registration.id ;" );
?>
<div class="container">
<CENTER><h2>view Booking Details</h2>
<table class="table table-bordered">
<th>place</th>
<th>Travelling Date</th>
<th>Total Cost</th>
<th>Stay cost</th>
<th>Food cost</th>
<th>Travelling cost</th>
<th>User ID</th>
<?php
while($row =mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['doj']; ?></td>
<td><?php echo $row['total'] ;?></td>
<td><?php echo $row['stay'] ;?></td>
<td><?php echo $row['food'] ;?></td>
<td><?php echo $row['travel'] ;?></td>
<td><?php echo $row['username'] ;?></td>
<td><img src='".$row['choose']."'/></td>";
</tr>
<?php
}
?>
</table>
</div>
i wrote my code,its executing but the problem is the data is not executing,can someone please help me out with my problem.
MysqlAdmin
In your table place details create a new entry call ID_regist.
After that change or give a number that correspond to your id in tabel Regist.
code php
For the connection create a connection.php.
<?php
$con= mysqli_connect("localhost", "root", "", "project");
if(!$con)
{
die('not connected');
}
?>
Makes your database more difficult to attack
Main code
<?php
include("connection.php");
?>
<div class="container">
<CENTER><h2>view Booking Details</h2>
<table class="table table-bordered">
<th>place</th>
<th>Travelling Date</th>
<th>Total Cost</th>
<th>Stay cost</th>
<th>Food cost</th>
<th>Travelling cost</th>
<th>User ID</th>
<?php
$sql=
"SELECT ".
"pld.name, ".
"pld.doj, ".
"pld.total, ".
"pld.stay, ".
"pld.food, ".
"pld.travel, ".
"pld.username ".
"FROM placedetails pld ".
"inner join registration reg ".
"on pld.ID_regist=reg.id;";
$result= mysqli_query($con, $sql);
if($result){
while($row =mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['doj']; ?></td>
<td><?php echo $row['total'] ;?></td>
<td><?php echo $row['stay'] ;?></td>
<td><?php echo $row['food'] ;?></td>
<td><?php echo $row['travel'] ;?></td>
<td><?php echo $row['username'] ;?></td>
<td><img src='".$row['choose']."'/></td>"; // first there is no row, call chose
</tr>
<?php
}
}
else{
die("Error"); //Something of the type mysqli_error(connection);
}
?>
</table>
</div>
Attention to the row call chose, that you don't use in your sql query.
If that does not solve your problems, tell me what happens when I try to help you.
You have to alter the place table and add registration_id. Then join with this field.
SELECT placedetails.name,placedetails.doj,placedetails.total,placedetails.stay,placedetails.food,placedetails.travel,registration.username
FROM placedetails inner join registration on registration.id=place.registration_id

My full data is not able to display on my web page from database

I wrote code to retrieve data from database and to print in form of tables on my web. I have stored 4 columns of data in my database but while retrieving it's only showing one column.
My database image
My webpage
My code:
<?php
$con = mysqli_connect("localhost", "root", "", "project");
if(!$con)
{
die('not connected');
}
$result= mysqli_query($con, "SELECT name, stay, food, travel,
SUM(stay + food + travel) AS totalamount,doj
FROM placedetails ");
?>
<div class="container">
<table class="table table-hover">
<thead>
<tr>
<th>place</th>
<th>stay cost</th>
<th>food cost</th>
<th>flight cost</th>
<th>Date of journey</th>
<th>Total cost</th>
</tr>
</thead>
<?php
while($row =mysqli_fetch_array($result))
{
?>
<tbody>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['stay']; ?></td>
<td><?php echo $row['food'] ;?></td>
<td><?php echo $row['travel'] ;?></td>
<td><?php echo $row['doj'] ;?></td>
<td><?php echo $row['totalamount'] ;?></td>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
Can anyone can tell where the mistake is?
And one more question: I want to diplay only the recent uploaded data on my web page. Suppose I have 4 names as mumbai, but uploaded at different times, I want to display the most recently added mumbai name on my web page
Can anyone help me out in this matter? I will be very thankful..
update your code as move tbody from php loop
<div class="container">
<table class="table table-hover">
<thead>
<tr>
<th>place</th>
<th>stay cost</th>
<th>food cost</th>
<th>flight cost</th>
<th>Date of journey</th>
<th>Total cost</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['stay']; ?></td>
<td><?php echo $row['food'] ;?></td>
<td><?php echo $row['travel'] ;?></td>
<td><?php echo $row['doj'] ;?></td>
<td><?php echo $row['totalamount'] ;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
1) <tbody> should be outside of while loop
2) if you want show only one record means no need to use while loop
3) if you want show recent record means just do descending sort by date column or id column
Query :
SELECT name, stay, food, travel, SUM(stay + food + travel) AS totalamount,doj FROM placedetails order by doj desc limit 1;
Table :
<tbody>
<?php
$row = mysqli_fetch_assoc($result); //fetch first record set only
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['stay']; ?></td>
<td><?php echo $row['food']; ?></td>
<td><?php echo $row['travel']; ?></td>
<td><?php echo $row['doj']; ?></td>
<td><?php echo $row['totalamount'];?></td>
</tr>
</tbody>

Categories