I've posted my code below. I can able to fetch the text values from database. But, i'm unable to fetch the image. i don't know where i made mistake?
try
{
$stmt = $conn->prepare("SELECT * FROM ebusers");
$conn->errorInfo();
$stmt->execute();
while($userrow = $stmt->fetch())
{
echo "<table class=glowing width=800 border=0 align=center cellpadding=0 cellspacing=0>";
echo "<tr>";
echo "<td height=40 colspan=3 class=user_id >User ID : " . $userrow['UserID'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor=wheat colspan=3> </td>";
echo "</tr>";
echo "<tr>";
echo '<td width=334 rowspan=9 bgcolor=wheat align=center >';
if( $userrow['UserProfilePicture'] >= '[BLOB - 0B]' )
{
echo '<img class=shadow_img width=160 height=180 src="data:image/png;base64,' . base64_encode($userrow['UserProfilePicture']) . '"/>';
}
else
{
echo '<img src=\'images/nophoto.gif\' class=shadow_img width=160 height=180 />';
}
echo "<tr>";
echo "<td bgcolor=wheat style=\"border-bottom-right-radius:5px; border-bottom-left-radius:5px;\" colspan=3> </td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "<br>";
}
}
catch(PDOException $e)
{
'Error : ' .$e->getMessage();
}
Related
Currently, I create a table that displays data from the database (JSON). In that table, I want to check is the data exists or not. Let's say if data is empty, I want to display "No booking data available at these moments".
The problem is, I don't know how to check the existing data. For now, if the data is empty, the table appears with <th> only and no words "No booking data available at these moments".
Below is my current code:
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = file_get_contents($url);
$json = json_decode($data);
if(empty($json)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
Try the following code:
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = #file_get_contents($url);
$json = json_decode($data);
if($json === FALSE && empty($json)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
I already solved my question. I just add "bookingList" at the empty json
<?php
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayAdminBookingDashboard?adminEmail=$Email";
$data = file_get_contents($url);
$json = json_decode($data);
if(empty($json->bookingList)){
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px;>";
echo "<h4 class='card-title'><i>No booking data available at this moments</i></h4>";
}else{
echo "<div class='card bg-light'>";
echo "<div class='card-body double' style='height: 400px; overflow-y: scroll;'>";
echo "<h4 class='card-title'>All Booking</h4>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>
<th>Requester</th>
<th>Factory</th>
<th>Room</th>
<th>Purpose</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody >";
foreach ($json->bookingList as $row) {
$status=$row->status;
if($status=="Approve"){
$color="color:green";
}else if($status=="Pending"){
$color="color:blue";
}else{
$color="color:red";
}
echo "<tr>";
echo "<td>" . $row->bookNo. "</td>";
echo "<td>" . $row->requestedBy. "</td>";
echo "<td>" . $row->facID. "</td>";
echo "<td>" . $row->roomName. "</td>";
echo "<td>" . $row->desc. "</td>";
echo "<td style='$color'><strong>" . $status ."</strong></td>";
echo "<td>";
echo "<a class='btn-view btn-primary btn-sm' href='../../view_booking/admin/view_booking_admin.php?Book_No=". $row->bookNo ."' data-toggle='tooltip'>View</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
echo "</div>";
echo "<div>";
}
?>
Following is the code
I want out put as
http://crysol.com/crysol_soft/Test/Screenshot_3.png
With following code I am getting output as
http://crysol.com/crysol_soft/Test/Screenshot_4.png
echo "<table border='1'>";
echo "<th>Name</th>";
echo "<th>Number</th>";
echo "<th>Status</th>";
echo '<tr>';
echo "<td rowspan='5'>Cat</td>";
for($i=1;$i<=5;$i++){
echo '<td>'.$i.'</td>';
echo " </tr>";
}
echo "<td rowspan='10'>Good</td>";
?>
What are the changes required
Here is the code with your desired output
used if condition for print only 1 time good column and used rowspan='5'
<?php
echo "<table border='1'>";
echo "<th>Name</th>";
echo "<th>Number</th>";
echo "<th>Status</th>";
echo '<tr>';
echo "<td rowspan='5'>Cat</td>";
for($i=1;$i<=5;$i++){
echo '<td>'.$i.'</td>';
if($i==1){
echo "<td rowspan='5'>Good</td>";
}
echo " </tr>";
}
?>
and also you can used this code
for($i=1;$i<=5;$i++){
echo '<tr>';
if($i==1){
echo "<td rowspan='5'>Cat</td>";
}
echo '<td>'.$i.'</td>';
if($i==1){
echo "<td rowspan='5'>Good</td>";
}
echo " </tr>";
}
Create Table inside td:
<?php
echo "<table border='1'>";
echo "<tr><th>Name</th>";
echo "<th>Number</th>";
echo "<th>Status</th></tr>";
echo "<tr><td style=''>Cat</td>";
echo "<td><table style='width:100%;'>";
for($i=1;$i<=5;$i++){
echo "<tr>";
echo "<td style='border-bottom:1pt solid black;'>".$i.'</td>';
echo "</tr>";
}
echo "</table></td>";
echo "<td>Good</td></tr>";
?>
Hi i am trying to submit the multiple form values only from one button i have 10 records and one record has one button of submit and 10 records have 10 buttons of submit what i want there should be only one button of submit and i can submit he whole 10 records from one button:
echo "<table class='table table-hover table-responsive table-bordered'>";
// our table heading
echo "<tr>";
echo "<th class='textAlignLeft'>Product Name</th>";
echo "<th>Price</th>";
echo "<th style='width:5em;'>Quantity</th>";
echo "<th>Image</th>";
echo "<th>Action</th>";
echo "</tr>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
//creating new table row per record
echo "<tr>";
echo "<td>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<div class='product-name'>{$name}</div>";
echo "</td>";
echo "<td>$" . number_format($price, 2, '.' , ',') . "</td>";
if(isset($quantity)){
echo "<td>";
echo "<input type='text' name='quantity' value='{$quantity}' disabled class='form-control' />";
echo "</td>";
echo "<td>";
echo "<td>";
echo "<button class='btn btn-success' disabled>";
echo "<span></span> Submitted!";
echo "</button>";
echo "</td>";
echo "</td>";
}else{
echo "<td>";
echo "<input type='number' name='quantity[]' value='1' class='form-control'/>";
echo "</td>";
echo "<td><img src='product-images/{$image}' width='60' height='60'</td>";
echo "<td>";
echo "<button class='btn btn-primary add-to-cart'>";
echo "<span></span>Submit to cart";
echo "</button>";
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
}
what i want only one button from i can submit all my values: Any help would be high appreciated:
$action = isset($_GET['action']) ? $_GET['action'] : "";
$product_id = isset($_GET['product_id']) ? $_GET['product_id'] : "1";
$name = isset($_GET['name']) ? $_GET['name'] : "";
$quantity = isset($_GET['quantity']) ? $_GET['quantity'] : "1";
$image = isset($_GET['image']) ? $_GET['image'] : "1";
if($action=='added'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> added to your cart!";
echo "</div>";
}
else if($action=='failed'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> failed to add to your cart!";
echo "</div>";
}
// left join to select products
$query = "SELECT p.id, p.name, p.price, p.image, ci.quantity
FROM products p
LEFT JOIN cart_items ci
ON p.id = ci.product_id
ORDER BY p.name";
$stmt = $con->prepare( $query );
$stmt->execute();
// count number of products returned
$num = $stmt->rowCount();
HTML CODE
<?php
// connect to database
include 'config/db_connect.php';
// page headers
$page_title="Cart";
include 'layout_head.php';
// parameters
$action = isset($_GET['action']) ? $_GET['action'] : "";
$name = isset($_GET['name']) ? $_GET['name'] : "";
$image = isset($_GET['image']) ? $_GET['image'] : "";
// display a message
if($action=='removed'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> was removed from your cart!";
echo "</div>";
}
else if($action=='quantity_updated'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> quantity was updated!";
echo "</div>";
}
else if($action=='failed'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> quantity failed to updated!";
echo "</div>";
}
else if($action=='invalid_value'){
echo "<div class='alert alert-info'>";
echo "<strong>{$name}</strong> quantity is invalid!";
echo "</div>";
}
// select products in the cart
$query="SELECT p.id, p.name, p.price, p.image, ci.quantity, ci.quantity * p.price AS subtotal
FROM cart_items ci
LEFT JOIN products p
ON ci.product_id = p.id";
$stmt=$con->prepare( $query );
$stmt->execute();
// count number of rows returned
$num=$stmt->rowCount();
if($num>0){
//start table
echo "<table class='table table-hover table-responsive table-bordered'>";
// our table heading
echo "<tr>";
echo "<th class='textAlignLeft'>Product Name</th>";
echo "<th>Price</th>";
echo "<th style='width:15em;'>Quantity</th>";
echo "<th>Sub Total</th>";
echo "<th>Action</th>";
echo "</tr>";
$total=0;
while( $row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
echo "<tr>";
echo "<td>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<div class='product-name'>{$name}</div>";
echo "</td>";
echo "<td>$" . number_format($price, 2, '.', ',') . "</td>";
echo "<td>";
echo "<div class='input-group'>";
echo "<input type='number' name='quantity[]' value='{$quantity}' class='form-control'>";
echo "<span class='input-group-btn'>";
echo "<button class='btn btn-default update-quantity' type='button'>Update</button>";
echo "</span>";
echo "</div>";
echo "</td>";
echo "<td>$" . number_format($subtotal, 2, '.', ',') . "</td>";
echo "<td>";
echo "<a href='remove_from_cart.php?id={$id}&name={$name}' class='btn btn-danger'>";
echo "<span></span> Delete from cart";
echo "</a>";
echo "</td>";
echo "</tr>";
$total += $subtotal;
}
echo "<tr>";
echo "<td><b>Total</b></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>$" . number_format($total, 2, '.', ',') . "</td>";
echo "<td>";
echo "</a>";
echo "</td>";
echo "</tr>";
echo "</table>";
}else{
echo "<div class='alert alert-danger'>";
echo "<strong>No products found</strong> in your cart!";
echo "</div>";
}
include 'layout_foot.php';
?>
Use name quantity[] instead of quantity.By this way you can receive post data as an array. After the loop use only one submit button.
echo "<input type='number' name='quantity[]' value='1' class='form-control'/>";
Then receive it by using foreach
foreach($_POST['quantity'] as $qty)
{
echo $qty;
//Here you will receive all the quantities one by one.
}
Form the code
<?php
echo "<table class='table table-hover table-responsive table-bordered'>";
// our table heading
echo "<tr>";
echo "<th class='textAlignLeft'>Product Name</th>";
echo "<th>Price</th>";
echo "<th style='width:5em;'>Quantity</th>";
echo "<th>Image</th>";
echo "</tr>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
//creating new table row per record
echo "<tr>";
echo "<td>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<div class='product-name'>{$name}</div>";
echo "</td>";
echo "<td>$" . number_format($price, 2, '.' , ',') . "</td>";
if(isset($quantity)){
echo "<td>";
echo "<input type='text' name='quantity[]' value='{$quantity}' disabled class='form-control' />";
echo "</td>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "</td>";
}else{
echo "<td>";
echo "<input type='number' name='quantity[]' value='1' class='form-control'/>";
echo "</td>";
echo "<td><img src='product-images/{$image}' width='60' height='60'</td>";
echo "<td>";
echo "</td>";
}
echo "</tr>";
}
echo "<tr><td colspan='4'>";
echo "<button class='btn btn-primary add-to-cart' type='submit'>";
echo "<span></span>Submit to cart";
echo "</button>";
echo "</td></tr>";
echo "</table>";
I wnt to show some pictures i have in a mysqli database, they are stored as blob.
But all i get is a A4 page with wierd text..
this is my code that i use too show(i connect to my database above this code):
echo "<table border=1>\n";
/*echo " <tr>\n";
echo " <th>Bild</th><th>Namn</th><th>Betygsättning</th>\n";
echo " </tr>\n";*/
while ($rad = mysqli_fetch_array($sql_result)) {
echo "<tr>";
echo "<td>";?> <img src="<?php echo $rad["Bild"]; ?>" height="100" width="100"> <?php echo "</td>";
echo "<td>"; echo $rad["Namn"]; echo "</td>";
echo "</tr>";
}
echo "</table>\n";
If you really want to embed the image to the generated html you should write it as this here:
echo "<td>";?> <img src="data:image/jpeg;base64,<?php echo base64_encode($rad["Bild"]); ?>" height="100" width="100"> <?php echo "</td>";
Here again with a little more clean code:
echo "<table border=\"1\">\n";
while($rad = mysqli_fetch_array($sql_result)) {
echo " <tr>\n";
echo " <td>\n";
echo " <img src=\"data:image/jpeg;base64," . base64_encode($rad["Bild"]) . "\" height=\"100\" width=\"100\" />\n";
echo " </td>\n";
echo " <td>" . $rad["Namn"] . "</td>";
echo " </tr>\n";
}
echo "</table>\n";
It seem that you forgot also to close your img tag.
echo '<table border=1>';
/*echo " <tr>\n";
echo " <th>Bild</th><th>Namn</th><th>Betygsättning</th>\n";
echo " </tr>\n";*/
while ($rad = mysqli_fetch_array($sql_result)) {
echo '<tr>
<td><img src="'.$rad["Bild"].'" height="100" width="100"></td>
<td>'.$rad["Namn"].'</td>
</tr>';
}
echo '</table>';
That should do it. While you are in a block of php code you can concatonate on it like above.
I've posted my code below. I can able to fetch the text values from database. But, i'm unable to fetch the image. i don't know where i made mistake?
try
{
$stmt = $conn->prepare("SELECT * FROM ebusers");
$conn->errorInfo();
$stmt->execute();
while($userrow = $stmt->fetch())
{
echo "<table class=glowing width=800 border=0 align=center cellpadding=0 cellspacing=0>";
echo "<tr>";
echo "<td height=40 colspan=3 class=user_id >User ID : " . $userrow['UserID'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor=wheat colspan=3> </td>";
echo "</tr>";
echo "<tr>";
echo '<td width=334 rowspan=9 bgcolor=wheat align=center >';
if( $userrow['UserProfilePicture'] >= '[BLOB - 0B]' )
{
echo '<img class=shadow_img width=160 height=180 src="data:image/png;base64,' . base64_encode($userrow['UserProfilePicture']) . '"/>';
}
else
{
echo '<img src=\'images/nophoto.gif\' class=shadow_img width=160 height=180 />';
}
echo "<tr>";
echo "<td bgcolor=wheat style=\"border-bottom-right-radius:5px; border-bottom-left-radius:5px;\" colspan=3> </td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "<br>";
}
}
catch(PDOException $e)
{
'Error : ' .$e->getMessage();
}