Could anybody tell me what I am going wrong?
I am trying to change CSS style asking with PHP.
<?php
include 'connect.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="10">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<title>Lista de mensajes</title>
</head>
<body>
<div class="container-fluid mb-10">
<table class="table table-striped fs-2">
<thead class="text-uppercase">
<tr>
<th scope="col" class="col-sm-2">fecha</th>
<th scope="col">mensaje</th>
<th scope="col" class="col-sm-1">prioridad</th>
</tr>
</thead>
<tbody>
<?php
$sql="SELECT * FROM mensajes WHERE 1 ORDER BY prioridad DESC,fecha DESC";
$resultado=mysqli_query($con,$sql);
while($row=mysqli_fetch_assoc($resultado)){
$id=$row['id'];
$hotel=$row['hotel'];
$mensaje=$row['mensaje'];
$fecha=new datetime($row['fecha']);
$fecha=$fecha->format('d-m-y H:i:s');
$prioridad=$row['prioridad'];
if($prioridad==true){
echo '<tr class="text-danger">';
}else{
echo '<tr>';
}
echo '<td scope="row">'.$fecha.'</td>
<td>'.$hotel." - ".$mensaje.'</td>
<td>'.$prioridad.'</td>
</tr>';
}
?>
</tbody>
</table>
<?php
if(!mysqli_close($con)){
die(mysqli_error());
}
?>
</div>
</body>
</html>
HTML output seems to be correct but I can only see the last entry in red
<table class="table table-striped fs-2">
<thead class="text-uppercase">
<tr>
<th scope="col" class="col-sm-2">fecha</th>
<th scope="col">mensaje</th>
<th scope="col" class="col-sm-1">prioridad</th>
</tr>
</thead>
<tbody>
<tr class="text-danger"><td scope="row">23-10-22 10:58:54</td>
<td>PLB - rojo OOOO?</td>
<td>1</td>
</tr><tr class="text-danger"><td scope="row">23-10-22 08:58:02</td>
<td>BPC - BPC y prioridad</td>
<td>1</td>
</tr><tr><td scope="row">24-10-22 08:01:54</td>
<td>BPK - TEST</td>
<td>0</td>
</tr><tr><td scope="row">23-10-22 10:26:29</td>
<td>BGA - Prueba BGA con prioridad</td>
<td>0</td>
</tr>
</tbody>
</table>
connect.php just make a connection to a mysql database with a single table.
I would like to show the text in red when the priority is true or 1
Thanks in advance
Firstly, don’t use while for database fetch. Use instead if
Secondly, something like $avar=areturn() will always be true, so you should define $row separately before the loop.
Related
I'm trying combine a table where fixtures are under their respective leagues [Headers] but i'm having a problem with the empty rows appearing in my table as its showing the empty rows instead of ignoring them
please check through the three pictures on how i want to shape my table:
SQL Table With Empty Cells In COL 1
HTML Table With Empty Rows Under Every Row
How I want My Table To Look Like after skipping empty Rows
My Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="Style.css">
</head>
<body>
<table class="Fixtures" border="1">
<tr>
<thead>
<th>League / Match</th>
</thead>
</tr>
<br>
<tr>
<th class="League ">Premier League</th>
</tr>
<tr >
<td>Arsenal - Man united</td>
</tr>
<tr>
<td>Chelsea - Newcastle</td>
</tr>
<th class="League">Spain La Liga</th>
<tr>
<td>Barcelona - Real Madrid</td>
</tr>
<tr>
<td>Sevilla - Real Sociedad</td>
</tr>
<tr>
<td>Alaves - Cadiz</td>
</tr>
<th class="League">Allsvenskan</th>
<tr>
<td>Elfsborg - Varberg</td>
</tr>
<tr>
<td>Kalmar - Varnamo</td>
</tr>
<tr>
<td>Malmo FF - Helsingborg</td>
</tr>
</table>
</body>
</html>
Instead of hiding them, you can just skip them:
while($row = $result->fetch_assoc()) {
if(!$row["COL 1"] && !$row["COL 2"]){
continue;
}
// Your other code here
}
I am trying to automatically page break if the data is more than 10 Im using mpdf + laravel + vue
This is my css code
<style>
div.breakNow { page-break-inside:avoid; page-break-after:always; }
</style>
This is my sale_pdf.blade.php
$i=0;
#foreach ($details as $detail)
$i++;
if( $i % 10 == 0 ){
<div class="breakNow">
<div id="details_inv">
<table class="table-sm">
<thead>
<tr>
<th>PRODUCT</th>
<th>UNIT PRICE</th>
<th>QUANTITY</th>
<th>DISCOUNT</th>
<th>TAX</th>
<th>TOTAL</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{$detail['code']}} ({{$detail['name']}})</td>
<td>{{$detail['price']}} </td>
<td>{{$detail['quantity']}}/{{$detail['unitSale']}}</td>
<td>{{$detail['DiscountNet']}} </td>
<td>{{$detail['taxe']}} </td>
<td>{{$detail['total']}} </td>
</tr>
} #endforeach
</tbody>
</table>
</div>
</div>
This is the current output.
Did I missed something? Thank you in advance
There is two way you can resolve this.
Option 1
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
.page-break {
page-break-after: always;
}
</style>
<body>
<h1>Page 1</h1>
<div class="page-break"></div>
<h1>Page 2</h1>
</body>
</html>
Option 2
Adding class between table row
$i=0;
#foreach ($details as $detail)
$i++;
<div class="{{ ( $i % 10 == 0 ) ? 'breakNow':''}}"></div>
#endforeach
All the other parts of my application are working but my users view cart is not working I do not know whether if it is about the indexing
I have tried using outer php
<!DOCTYPE html>
<html>
<head>
<title>View table</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs /popper.js/1.14.7/umd/popper.min.js"></script>
</head>
<body>
<table class="table">
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">brand</th>
<th scope="col">flavour/type</th>
<th scope="col">quantity</th>
<th scope="col">Number of units</th>
<th scope="col">Number of packets</th>
<th scope="col">price</th>
<th scope="col">Cost</th>
<th scope="col">Picture</th>
<th scope="col">D</th>
</tr>
</thead>
<tbody>
<?php
require_once("config.php");
error_reporting(0);
$email_address=$_SESSION['email_address'];
$sql="SELECT product_name ,brand,flavour_type,quantity,number_of_units,price ,units,image_path
FROM gokcen.product NATURAL JOIN gokcen.cart
WHERE cart.email_address=:email_addres";
$stmt=$db->prepare($sql);
$stmt->bindParam(':email_address',$email_address);
$stmt->execute();
$result=$stmt->fetchAll();
foreach($result as $product)
{
?> <tr>
<td><?php echo $product['product_name'];?></td>
<td><?php echo $product['brand'];?></td>
<td><?php echo $product['flavour_type'];?></td>
<td><?php echo $product['quantity'];?></td>
<td><?php echo $product['number_of_units'];?></td>
<td><?php echo $product['units'];?></td>
<td><?php echo $product['price'];?></td>
<td><?php echo $product['price']* $prouct['units'];?></td>
<td> <img src="pics/<?php echo $product['image_path'];?>" width="80" height="80"/></td>
<td><a href="deletefromcart.php?item=<?echo product['product_name'];?>"> delete <a></td>
</tr>
<?php }?>
</tbody>
</table>
<a href="#" class="btn btn-primary" >Buy</a>
</body>
</html>
There are no results It does not give any errors it shows the header part only and Im not sure about the indexing.
there are several typos in your code.
When I am right there should be another "s" at the end? cart.email_address=:email_addres
There is a "d" missing at line <?php echo $product['price']* $prouct['units'];?>
You also missed the "$" sign at this point as well as the "php" after the question mark: <?echo product['product_name'];?>
You should set display_errors to On in your php.ini and comment out the error_reporting(0); for debugging purposes :)
Greetings
You have a typo email_addres email_address.
WHERE cart.email_address=:email_addres";
$stmt->bindParam(':email_address',$email_address);
Thank you guys you are the best you rock my coding life It was the typos and also that
I had not put a
session_start()
To initialize the value of $email_address on
$email_address=$_SESSION['email_address'];
All the best!
Currently, I am working on my datatable to display the detail from the database. I am using the php myadmin for the database. But it only manage to display the detail only but not the pagination, sorting and searching is not working. I have followed some other tutorials but it still doesn't work.
<?php
$conn = mysqli_connect("localhost", "root", "", "jiaen");
$sql = "SELECT * FROM stock LEFT OUTER JOIN category ON stock.categoryid=category.categoryid order by stockCode";
//Execute connection
$result = mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial | Datatables Jquery Plugin with Php MySql and Bootstrap</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
</script>
</head>
<body>
<br /><br />
<div class="container">
<h3 align="center">Datatables Jquery Plugin with Php MySql and Bootstrap</h3>
<br />
<div class="table-responsive">
<table id="stock" class="table table-striped table-bordered" >
<thead>
<tr>
<td>Stock Code</td>
<td>Stock Name</td>
<td>Stock Category</td>
<td>Quantity</td>
<td>Price (RM)</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td>'.$row["stockCode"].'</td>
<td>'.$row["stockName"].'</td>
<td>'.$row["categoryName"].'</td>
<td>'.$row["quantity"].'</td>
<td>'.$row["price"].'</td>
<td>Stock In</td>
<td>R&D</td>
<td>Remark Stock</td>
<td>Modify</td>
<td>Delete</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</div>
//Javascript part for datatable
<script>
$(document).ready(function() {
$('#stock').DataTable();
} );
</script>
</body>
</html>
Your <thead> contains a <tr> which is full of <td> tags instead of <th> tags.
It has 6 tags, so your table will have 6 columns.
Your <tbody> on the other hand has 10 <td> tags inside each <tr> tag.
10 will not fit into 6.
Hello I write PHP header for downloading excel.
If I have 1 table I can set the width of <td> successfully by use width attribute
but if I have two table it's not working. How could I do? because I need multiple table in my excel page file
<?php
header("Content-Type: application/vnd.ms-excel; charset=TIS-620");
header('Content-Disposition: attachment; filename="report_schedule_teacher.xls"');#ชื่อไฟล์
?>
<html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=TIS-620" />
</head>
<body>
<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="300">Hello1</td>
<td width="400">Hello2</td>
</tr>
</thead>
<tbody>
<tr>
<td>World1</td>
<td>World2</td>
</tr>
</tbody>
</table>
<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="300">Why I cannot set width if I have multiple table</td>
<td width="400">Noooo</td>
</tr>
</thead>
<tbody>
<tr>
<td>kub</td>
<td>pom</td>
</tr>
</tbody>
</table>
</body>
</html>
Excel, when reading HTML files, really only has one HTML table. If you look at the Excel window you'll see that physically it's just a single table. If you insist on separating the data (which makes no difference to Excel) you can use multiple table bodies:
<html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=TIS-620" />
</head>
<body>
<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="300">Hello1</td>
<td width="400">Hello2</td>
</tr>
</thead>
<tbody>
<tr>
<td>World1</td>
<td>World2</td>
</tr>
</tbody>
<thead>
<tr>
<td width="300">Why I cannot set width if I have multiple table</td>
<td width="400">Noooo</td>
</tr>
</thead>
<tbody>
<tr>
<td>kub</td>
<td>pom</td>
</tr>
</tbody>
</table>
</body>
</html>
Output:
By the way, you are abusing MIME types terribly here! This document is not application/vnd.ms-excel or application/xhtml+xml, it's text/html and should not be saved with an XLS extension. Excel can read HTML files, but that doesn't make HTML files Excel files!