Implement a table using html - html

I have this template table :
How to implement this us table html (<tr> and <td>) ?
And if I have a dynamic data from a 2 database that mean for football in database 1 I have players in database 2 (note we suppose we have implemented a function to get from database I need only view) how to implement this?
Please show update figure for good understand :
For good understand my question like this function :
for(i = 0, i<2 , i++)
{
for(j = 1 , j< 5 , j++)
{ <table>
<tr> <td> i </td>
.......................
View :
0 1
1 2 3 4 1 2 3 4

Something like this maybe?
td{
border:1px solid black;
}
td[colspan="3"]{
text-align:center;
}
table{
border-collapse:collapse;
}
<table>
<tr><td colspan="3">Header1</td><td colspan="3">Header2</td></tr>
<tr><td>Item 1</td><td>Item 2</td><td>Item 3</td><td>Item 4</td><td>Item 5</td><td>Item 6</td></tr>
</table>
You can achieve it using the colspan attribute. By setting the colspan of the columns in the top row larger than those beneath, we can achieve the same effect.
For text-align:center, we can use the CSS selector td[colspan="3"].
To get rid of spaces between the columns, we use border-collapse:collapse.

try this:
<table border="1">
<tr>
<th colspan="3">Header One</th>
<th colspan="3">Header two</th>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
<td>C5</td>
<td>C6</td>
</tr>
</table>
And this link can help you

Related

Regex to select third TD from every TR in HTML Table

Here is the table example given below.
From the table, I want third column means third TD from every TR.
<table>
<tbody>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>Five</td>
<td>Six</td>
<td>Seven</td>
<td>Eight</td>
</tr>
</tbody>
</table>
I tried
<td>(.*?)</td>
this matches every td. Please tell me regex to select every third TD
Are you ONLY looking for regex solution?
I have some solution from CSS and JavaScript. Hopefully it helps you.
From CSS
td:nth-of-type(3) {
color: red;
}
From Javascript
const thirdTD = document.querySelectorAll('td:nth-of-type(3)')
thirdTD.forEach(thirdTdEl => thirdTdEl.style.background = "green")

How can i add tr inside td with bootstrap-4 table?

I want to add two rows inside a td like below picture but I can't find any solution of this.
You can do by using nested table
http://www.corelangs.com/html/tables/table-inside-table.html
You Have Asked (How can i add tr inside td)
To have tr inside td the only way is create another table inside td than you can have tr inside td.
Example :
<table>
<tr>
<td>
<table>
<tr>
<td>
...
</td>
</tr>
</table>
</td>
</tr>
</table>
But the image you have added it represent that you want to merge two rows for that you need to use Row Span.
Example for Row Span ( https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_td_rowspan )
Try using rowspan attribute in the cell.
https://www.w3schools.com/tags/att_td_rowspan.asp
Maybe you can use the rowspan attribute on td tags in your HTML: https://www.w3schools.com/tags/att_td_rowspan.asp
Example:
<table>
<tr>
<th>B/B LC NO Value USD</th>
<th>ABP Value USD</th>
<th>Exp N& Date</th>
</tr>
<tr>
<td rowspan="2">$ xxxxx<br/>$ -</td>
<td>$100</td>
<td>$50</td>
</tr>
<tr>
<td>$1</td>
<td>$80</td>
</tr>
</table>
You can give the fiels that you don't want to divide into two rowspan="2" and then skip the fields that would normally be under them.
<table>
<tr>
<td rowspan="2">Margaret Nguyen</td>
<td>427311</td>
<td><time datetime="2010-06-03">June 3, 2010</time></td>
<td>0.00</td>
</tr>
<tr>
<td>533175</td>
<td><time datetime="2011-01013">January 13, 2011</time></td>
<td>37.00</td>
</tr>
</table>

HTML align labels and texts

I am trying to make a view that looks like the image below
My view contains:
<span>Title :</span>
<span>#ViewBag.Movie</span>
<div>Date : #ViewBag.Date</div>
<div>Transaction Number : #ViewBag.TransactionNo</div>
<div>Timing : #ViewBag.Timing</div>
<div>Rating : #ViewBag.Rating</div>
<div>Hall : #ViewBag.Hall</div>
Controller.cs:
ViewBag.Movie = "movie a";
ViewBag.Date = "3-Nov-2017";
ViewBag.TransactionNo = "1234";
ViewBag.Timing = "7:30pm";
ViewBag.Rating = "PG13";
ViewBag.Hall = "3";
How do I align the view to make it look like the image?
It is better to use HTML table if you are creating a table structure
Example:
<table>
<tr>
<th>Movie Information</th>
</tr>
<tr>
<td>Title</td>
<td>: movie a</td>
</tr>
<tr>
<td>Date</td>
<td>: 3-Nov-2017</td>
</tr>
<tr>
<td>Transaction Number</td>
<td>: 1234</td>
</tr>
<tr>
<td>Title</td>
<td>: movie a</td>
</tr>
</table?
First of all, you should get some knowledge about html and css.
Your idea starts well when you separate the title from the value with <span></span>, but then in the next lines you're using a single div for each line. Why? If you want to align or separate items on your screen, then you must put those items in their own elements, like div or span.
<div class='myLabel'>Title :</div><div class='myValue>#ViewBag.Movie</div>
<div class='myLabel'>Date :</div><div class='myValue>#ViewBag.Date</div>
then add a css-stylesheet, containing something like
.myLabel {
width: 150px;
}
.myValue {
float: left;
}

HTML's Table TD with default value

Is there any way to fill the empty <td></td>, if data does not exist in this?
<table><tr><td></td><td>1</td><td></td></tr></table>
Change it to:
<table><tr><td>Not Data</td><td>1</td><td>No Data</td></tr></table>
Not with HTML itself.
Usually you would do this by generating the HTML using a data in a programming language and a template, with template logic used to insert a default value if none came from the data.
A little bit hackish, because it changes only visual aspect. You can do that with CSS:
table, td {border: 1px solid black; padding: 4px; border-collapse: collapse}
td:empty::before {content: "No Data"}
<table>
<tr>
<td></td>
<td>Real data</td>
<td></td>
</tr>
</table>
Won't really work just with html.
it depends on how you build your HTML-DOM. If it is just a pure HTML-file (*.html ) you could check for value by adding some JavaScrit/JQuery.
But if you are trying to do this, make sure to give your table/tr or td to give element-ids.
<table>
<tr id="1">
<td id="1_1"></td>
<td id="1_2">1</td>
<td id="1_3"></td>
</tr>
</table>
<script type="text">
/* For the amount of rows */
for(var outeri = 1; outeri <= 1; outeri++)
{
/* For the amount of columns */
for(var ineri = 1; ineri <= 3; ineri)
{
var innertd = String(outeri + '_' + ineri);
if(document.getElementById(inntertd).innerHTML == '')
{
document.getElementById(inntertd).innerHTML = 'No Data';
}
else {continue;}
}
}
</script>
This example is not very realistic and more likely not to be done unless your table is just static.
you can add an empty space:
This can be achieved in many ways, here are 2 (c# and jquery)
Solutions:
c#:
Use razor as in the following:
<table>
<thead>
<tr>
<td>Name</td>
<td>Date</td>
</tr>
</thead>
<tbody>
<tr>
#{
if(data)
{
<td>#data.name</td>
<td>#data.date</td>
}
else
{
<td colspan="2">NO DATA</td>
}
}
</tr>
</tbody>
</table>
jQuery:
Select the table and change the html depending on if there is any data
$(document).ready(function()
{
var table = $("table-selector");
var isData = $("data-selector").length;
if(!isData){
table.html("customize HTML right here, considering 'colspan' in case
there is a headers row as well")
}
});

A table row was 2 columns wide and exceeded the column count established by the first row (1)

I want to validate my page but w3c keeps giving me this warning. I want to get rid of it but I can't seem to find the cause of it.
It gives me this error:
A table row was 2 columns wide and exceeded the column count established by the first row (1).
Table and CSS code:
<table>
<tr>
<td>Contact informatie</td>
<tr>
<td>Adres:</td>
<td>Jan van der Heydenstraat 61</td>
<tr>
<td>Postcode:</td>
<td>1223 BG</td>
<tr>
<td>Plaats:</td>
<td>Hilversum</td>
<tr>
<td>Email:</td>
<td>info#blabla.nl</td>
<tr>
<td>Telefoon:</td>
<td>06-31903706</td>
</tr>
</table>
table {
border:none;
padding-left:75px;}
td:first-child {
width:135px;
border:none;
text-align:left;}
td+td {
border:none;
text-align: left;}
Anyone any suggestions?
It means exactly what it says. One of the rows in your table has too many columns. Specifically, the first row has less columns that a subsequent row. But we can't do much unless you post some code.
Edit
The markup for the table is incorrect.
You only have one cell in the first row (or do what PeeHaa suggested)
You need to close off each row with </tr>
Just change this:
<tr>
<td>Contact informatie</td>
</tr>
To this:
<tr>
<td colspan="2">Contact informatie</td>
</tr>
YOu should always close you tablerows (tr): </tr>.
Final version:
<table>
<tr>
<td colspan="2">Contact informatie</td>
</tr>
<tr>
<td>Adres:</td>
<td>Jan van der Heydenstraat 61</td>
</tr>
<tr>
<td>Postcode:</td>
<td>1223 BG</td>
</tr>
<tr>
<td>Plaats:</td>
<td>Hilversum</td>
</tr>
<tr>
<td>Email:</td>
<td>info#vazcreations.nl</td>
</tr>
<tr>
<td>Telefoon:</td>
<td>06-31903706</td>
</tr>
</table>
In extension to what SimpleCoder said, if you have the first row of a table have only one column, then the futher ones can have no more then one column. If you want to get around this you need to put a table inside the cell i.e.
<td>
<table>
<tr>
<td><!-- Content here --></td>
</tr>
</table>
</td>