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
}
Related
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.
I have a table that I generate using PHP, with the fields of name, id and the name of the file that contains the person's photo. How can I store the information of each row of the table in variables and use them in another PHP page, so that when clicking on the name of the person that appears in the table, a PDF document that I generated with FPDF is opened and use the data from the table (name and file name of the photograph) to fill the PDF.
This is the code where the table is generated:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php
$link = new PDO('mysql:host=localhost;dbname=employers', 'root', '');
?>
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>FILENAME</th>
</tr>
</thead>
<?php foreach ($link->query('SELECT * from employers') as $row){ ?>
<tr>
<td><?php echo $row['ID'] ?></td>
<td><?php echo $row['NAME'] ?></td>
<td><?php echo $row['FILENAME'] ?></td>
<td><a href="/TCPDF/examples/example_051.php?ID=<? echo
$row['ID'];?>">view</a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
This is the part of the code that generates the PDF where I want to use the information that comes from the table, the variables are the
$someString
:
$pdf->setFont('calibri', '', 48);
// add a page
$pdf->AddPage();
// Print a text
$subtable = '<table border="1" cellspacing="6" cellpadding="4"><tr><td><h1 style="font-size: 45px;text-align:left;"><br><br><br> '.$someString4.'</h1></td></tr><tr><td><h1 style="font-size: 150px;text-align:LEFT;"> '.$someString3.'</h1></td></tr></table>';
$html = '
<table cellpadding="10" cellspacing="7" border="1" style="text-align:center;">
<tr style="position:absolute; left:780px; top:120px;">
<td>'.$subtable.'</td>
<td><br><br><img src="images/'.$someString2.'" border="0" height="300" width="200" align="bottom" /><h2 style="font-size: 30px;">'.$someString.'</h2></td>
</tr>
</table>';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();
I have 5 dropdowns on a tab of a website. I have a database table in MS SQL Server. The table has all the data of 5 dropdowns with one of the fieldNames called Region_Name, say the Region_Names are A, B, C, D, and E. I have written codes to display a table and enabled row editing for one of the RegionNames. Now, I am wondering if I could modify the same codes to display associated table with row editing enabled using different queries when a dropdown is clicked. That could reduce the code repetition and improve the performance. But I do not know how to achieve this. Could anyone please give me some hints? I am using PHP PDO to connect to the database.
My codes to display the table is shown below. I am using Datatables plugin and tableExport Jquery plug in. For simplicity, I have not copied the links and libraries for plugins. I can show my edit.php if that will be helpful.
<?php
require_once('include/database.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Matrix</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta http-equiv="content-type" content="text/html" charset="UTF-8">
<script src="//code.jquery.com/jquery-1.12.3.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<header>
</header> <br/>
<div id="container">
<table id="myTable" class="display" cellpadding="0px" cellspacing="0px"
width="100%">
<thead>
<tr>
<th style="width: 1px">ID</th>
<th style="width: 1px">Site</th>
<th style="width: 1px">Location</th>
<th style="width: 1px">Remarks</th>
<th width="1px">Action</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $conn->prepare("SELECT * FROM MATRIX WHERE
Region_Name='Charlotte'");
$stmt ->execute();
$result = $stmt->fetchAll();
foreach($result as $row) {
?>
<tr>
<td><?=$row['ID'];?></td>
<td><?= $row['Site']; ?></td>
<td><?= $row['Location']; ?></td>
<td><?= $row['Remarks']; ?></td>
<td> Edit</td>
</tr>
<?php
}
?>
</tbody>
</table>
<br/>
</div>
</body>
</html>
You may use SELECT table_name FROM information_schema.tables WHERE table_schema = '<your database name>' to get all the table in your database.
You can also get all the columns of table with this query
select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='<your table name>'
how can I save the colour into database ? here is my coding.. I can change the table colour, but it doesn't save into database. While I'm open it again, the colour will turn to normal..
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<html>
<title>Test</title>
<head>
<script type="text/javascript">
function colourRow1(rowNumber) {
//some code to change the colour of the row indicated by the number
alert("change row 1 background colour");
var tr = document.getElementById('table1')
.getElementsByTagName('tr')[rowNumber-1];
tr.style.backgroundColor = 'blue';
}
</script>
</head>
<body>
<table name="table1" id="table1" border="1">
<thead>
<th>heading1</th>
<th>heading2</th>
<th>heading3</th>
</thead>
<tbody>
<tr id="row1">
<td>1,1</td>
<td>1,2</td>
<td>1,3</td>
</tr>
<tr id="row2">
<td>2,1</td>
<td>2,2</td>
<td>2,3</td>
</tr>
<tr id="row3">
<td>3,1</td>
<td>3,2</td>
<td>3,3</td>
</tr>
</tbody>
</table>
<button type="button" onClick="colourRow1(1)" action="colourupdate.php">Change Row 1</button>
</body>
</html>
how can I save the colour into database ? here is my coding.. I can change the table colour, but it doesn't save into database. While I'm open it again, the colour will turn to normal..
You need to maintain another table for storing the color history..
Table structure like this
id | rowno | color
you need to store row number and color for each button click using a ajax call.
Other Method is
Store row id and color as a Session for a particular period of time ..
$_SEESION['rowid']=$value;
$_SEESION['rowid']=$color;
From the following HTML i need to extract email address only to save it in database. I need to pull it in array, what i was planning is to use jquery/ajax to pull all email using dom and save it to another page using ajax ,but the problem is that
<td> have no unique identification with other <td> i.e i can do it if td has class or id name
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" border="1">
<tr></tr>
<tr>
<td>NAME</td>
<td>ADDRESS</td>
<td>PHONE</td>
<td>EMAIL</td>
</tr>
<tr>
<td>wwqw</td>
<td>qww</td>
<td>ew</td>
<td>email#exmaple.com</td>
</tr>
<tr>
<td>e</td>
<td>wew</td>
<td>ew</td>
<td>emai1l#exmaple.com</td>
</tr>
<tr>
<td>e</td>
<td>ewe</td>
<td>we</td>
<td>email2#exmaple.com</td>
</tr>
<tr>
<td>we</td>
<td>we</td>
<td>we</td>
<td>emai3l#exmaple.com</td>
</tr>
<tr>
<td>ww</td>
<td>w</td>
<td>w</td>
<td>emai4l#exmaple.com</td>
</tr>
</table>
</body>
</html>
I need to grab email address and store in array like below
Array
(
[0] => email#exmaple.com
[1] => emai1l#exmaple.com
[2] => email2#exmaple.com
[3] => emai3l#exmaple.com
[4] => emai4l#exmaple.com
)
<td> can have variable class and id , so its very hard to use jquery etc to pull them. I am obstructed by it . Any help wil be appreciated
Using jQuery-->
$(document).ready(function() {
$('tr').find('td:last').each(function(){
var t = $(this).text();
if(typeof(t) === 'string' && t.indexOf('#') >-1) alert(t);
})
});
do not use jquery, regular expression will make your job easy.
$string='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" border="1">
<tr></tr>
<tr>
<td>NAME</td>
<td>ADDRESS</td>
<td>PHONE</td>
<td>EMAIL</td>
</tr>
<tr>
<td>wwqw</td>
<td>qww</td>
<td>ew</td>
<td>email#exmaple.com</td>
</tr>
<tr>
<td>e</td>
<td>wew</td>
<td>ew</td>
<td>emai1l#exmaple.com</td>
</tr>
<tr>
<td>e</td>
<td>ewe</td>
<td>we</td>
<td>email2#exmaple.com</td>
</tr>
<tr>
<td>we</td>
<td>we</td>
<td>we</td>
<td>emai3l#exmaple.com</td>
</tr>
<tr>
<td>ww</td>
<td>w</td>
<td>w</td>
<td>emai4l#exmaple.com</td>
</tr>
</table>
</body>
</html>';
echo "<pre>";
$pattern="/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)#([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i";
preg_match_all($pattern, $string, $matches);
print_r($matches[0]);
<?php
include('simple_html_dom.php');
$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" border="1">
<tr></tr>
<tr>
<td>NAME</td>
<td>ADDRESS</td>
<td>PHONE</td>
<td>EMAIL</td>
</tr>
<tr>
<td>wwqw</td>
<td>qww</td>
<td>ew</td>
<td>email#exmaple.com</td>
</tr>
<tr>
<td>e</td>
<td>wew</td>
<td>ew</td>
<td>emai1l#exmaple.com</td>
</tr>
<tr>
<td>e</td>
<td>ewe</td>
<td>we</td>
<td>email2#exmaple.com</td>
</tr>
<tr>
<td>we</td>
<td>we</td>
<td>we</td>
<td>emai3l#exmaple.com</td>
</tr>
<tr>
<td>ww</td>
<td>w</td>
<td>w</td>
<td>emai4l#exmaple.com</td>
</tr>
</table>
</body>
</html>';
$dom = new simple_html_dom();
$dom->load($html);
$table = $dom->find('table', 0);
if($table){
foreach($table->find('tr') as $row) {
$rowData = array();
foreach($row->find('td') as $cell) {
$rowData[] = $cell->innertext;
}
$theData[] = $rowData;
}
print_r($theData);
}
?>
Or you can do it with jquery
$(document).ready(function() {
$('tr').find('td:last').each(function(){
console.log($(this).text());
})
});