CSS Clearing Table Borders - php

Any ideas, how to make table look like this (marked with red circles) that there are no border and background color?

table
{
border-collapse:separate;
border-spacing:10px 50px;
}
or whatever you want your spacing to be

You can give your tds some padding?
JSFiddle
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<!-- more rows -->
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
</table>
CSS:
tr td:nth-of-type(2){
padding:0 20px;
}

Related

How do I create a 10x10 addition table using PHP?

I need a hand with this project I am working on, I cant seem to find out why my code isn't working. My goal is to display a addition table similar to this one:
My code for this table so far is:
<!DOCTYPE html>
<html>
<body>
<?php
$cols = 10;
$rows = 10;
?>
<?php echo "<table border=\"1\">";
<?php echo "<table>";
for($a = 1; $a < $rows;$a++)
echo'<tr>';
for($b = 1;$b < $cols; $b++);
echo '<td>'($answer = $a + $b); '</td>'
echo"</table>";
?>
<br>
</body>
</html>
There are a bunch of typos and omissions. The worst are the missing or extraneous semicolons
Here is working code using array notation
https://onlinephp.io/c/a97d8
<?php
$cols = 10;
$rows = 12;
$table[]="<table><tbody><tr><td>+</td>";
for($a = 1; $a < $rows;$a++) {
$table[] = "<td>$a</td>";
for($b = 1;$b < $cols; $b++) $table[]= "<td>".($answer = $a + $b)."</td>";
if ($a<$rows-1) {
$table[] = "</tr>";
$table[] = "<tr><td>$a</td>";
}
}
$table[] = "</tr></tbody></table>";
echo implode($table);
?>
Output
Note the CSS - it is quite complex
table tr:nth-of-type(2n+3) : stripe from 3rd row
table {
border-collapse: collapse;
font-weight: bold;
color: blue;
font-family: Arial, Helvetica, sans-serif;
}
table td {
border: 1px solid #ccc;
width: 2em;
padding: 5px;
text-align: center;
}
table tr:first-of-type {
background-color: gold;
color: black;
}
table tr td:first-child {
background-color: pink;
color: black;
}
table tr:first-child>td:first-child {
background-color: orange;
}
table tr:nth-of-type(2n+3) {
background-color: #f2f2f2;
}
<table>
<tbody>
<tr>
<td>+</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
</tr>
<tr>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
</tr>
<tr>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
</tr>
<tr>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
</tr>
</tbody>
</table>
Easiest way to do this is with PHP and CSS Grid:
https://paiza.io/projects/oHTe6JJGbeXX85Hij6X0VQ?language=php
<div class="table">
<?php
$rows = 10;
$cols = 10;
for($i=0; $i<$rows+1; $i++)
{
for($j=0; $j<$cols+1; $j++)
{
echo "<div>";
echo $i == 0 && $j == 0 ? "+" : $i + $j;
echo "</div>";
}
}
?>
</div>
Result:
.table {
display: grid;
grid-template-columns: repeat(11, 1fr);
}
.table > div {
font-family:sans-serif;
padding: 5px 5px;
border: solid 1px;
text-align: center;
}
.table > div:first-child {
background-color: orange;
}
.table > div:nth-child(11n + 12) {
background-color: pink;
}
.table > div:nth-child(n+2):nth-child(-n+11) {
background-color: goldenrod;
}
<div class="table">
<div>+</div><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div><div>7</div><div>8</div><div>9</div><div>10</div><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div><div>7</div><div>8</div><div>9</div><div>10</div><div>11</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div><div>7</div><div>8</div><div>9</div><div>10</div><div>11</div><div>12</div><div>3</div><div>4</div><div>5</div><div>6</div><div>7</div><div>8</div><div>9</div><div>10</div><div>11</div><div>12</div><div>13</div><div>4</div><div>5</div><div>6</div><div>7</div><div>8</div><div>9</div><div>10</div><div>11</div><div>12</div><div>13</div><div>14</div><div>5</div><div>6</div><div>7</div><div>8</div><div>9</div><div>10</div><div>11</div><div>12</div><div>13</div><div>14</div><div>15</div><div>6</div><div>7</div><div>8</div><div>9</div><div>10</div><div>11</div><div>12</div><div>13</div><div>14</div><div>15</div><div>16</div><div>7</div><div>8</div><div>9</div><div>10</div><div>11</div><div>12</div><div>13</div><div>14</div><div>15</div><div>16</div><div>17</div><div>8</div><div>9</div><div>10</div><div>11</div><div>12</div><div>13</div><div>14</div><div>15</div><div>16</div><div>17</div><div>18</div><div>9</div><div>10</div><div>11</div><div>12</div><div>13</div><div>14</div><div>15</div><div>16</div><div>17</div><div>18</div><div>19</div><div>10</div><div>11</div><div>12</div><div>13</div><div>14</div><div>15</div><div>16</div><div>17</div><div>18</div><div>19</div><div>20</div></div>

XPath: Get tables with exactly two columns

<table>
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
<table>
<tr>
<td>1</td>
<td>A</td>
</tr>
<tr>
<td>2</td>
<td>B</td>
</tr>
</table>
<table>
<tr>
<th>1</th>
<td>A</td>
</tr>
<tr>
<th>2</th>
<td>B</td>
</tr>
</table>
<table>
<tr>
<th>1</th>
<th>A</th>
</tr>
<tr>
<td>2</td>
<td>B</td>
</tr>
</table>
How do I get only the table(s) with exactly 2 columns, whether its both th in a single tr, or both td or either, but two columns.
If you want to check if count of either th or td in each row equals 2, this is one possible way :
//table[tr[count(td|th) = 2]]
And if child of tr is always either th or td, never other element that you don't want to consider in the count, then you can just say count all child elements :
//table[tr[count(*) = 2]]
Notice that the above will count only direct child, not including descendants.

HTML to PDF conversion rowspan not working

I am using third party code for HTML To PDF conversion is working good.But this cannot accept rowspan why?? Here is my code.
require('WriteHTML.php');
$pdf=new PDF_HTML();
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(true, 15);
$pdf->AddPage();
$pdf->SetFont('Arial','B',14);
$pdf->WriteHTML('<para><h1>Title</h1>');
$pdf->SetFont('Arial','B',7);
$htmlTable="<TABLE border='1'>
<TR height='40'>
<TD>S.NO</TD>
<TD>Type Of Beneficiary</TD>
<TD>Expected</TD>
<TD>No.Of Beneficiary</TD>
<TD>No.Of Packs Issued</TD>
<TD>Ave.monthly Usage</TD>
<TD>Balance Stock Available</TD>
</TR>
<TR>
<TD>1</TD>
<TD>Adolescents Girls</TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD ></TD>
</TR>
<TR>
<TD rowspan='4'>2</TD>
<TD>Normal</TD>
<TD>ALLOTMENT NO</TD>
<TD>QUANTITY</TD>
<TD>QUANTITY</TD>
<TD>QUANTITY</TD>
<TD rowspan='4'></TD>
</TR>
<TR>
<TD>LSCS</TD>
<TD>ALLOTMENT NO</TD>
<TD>QUANTITY</TD>
<TD>QUANTITY</TD>
<TD>QUANTITY</TD>
</TR>
<TR>
<TD>Puperial Sterilization</TD>
<TD>ALLOTMENT NO</TD>
<TD>QUANTITY</TD>
<TD>QUANTITY</TD>
<TD>QUANTITY</TD>
</TR>
<TR>
<TD>Total</TD>
<TD>ALLOTMENT NO</TD>
<TD>QUANTITY</TD>
<TD>QUANTITY</TD>
<TD>QUANTITY</TD>
</TR>
<TR>
<TD>3</TD>
<TD>Women Prison Inmates</TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD>4</TD>
<TD>Women IMH Inmates</TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD>5</TD>
<TD>Total</TD>
<TD> </TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>";
$pdf->WriteHTML2("$htmlTable");
$pdf->Output();
It seems FPDF doesn't support rowspan:
FPDF does not recognize rowspan or colspan. Here is a workaround that
you can try, using empty cells and the border attribute for Cell.
by Sean (emphasis mine) - here is the full answer
Rowspan and Colspan supporting the TCPDF Library.And also easy configration this one. Library path http://www.tcpdf.org/ and coding path http://www.tcpdf.org/examples/example_048.phps. just change the path only. require_once('tcpdf.php');

php strip_tags not outputting whole string

i have this table as a variable i want to use strip_tags function on:
<?php $tbl='
<table id="patients">
<tr>
<th>Pt. username</th>
<th>Pt. number</th>
<th>Full Name</th>
<th>Added on</th>
</tr> <tr><td><a href="profile.php?username=fringo123"</a>fringo123</td>
<td>3</td>
<td>fringo123 shreiwekh</td>
<td>2014-02-12 22:16:53</td>
</tr> <tr class="alt"><td><a href="profile.php?username=kamal"</a>kamal</td>
<td>24</td>
<td>kamal kab</td>
<td>2014-03-06 03:01:24</td>
</tr> <tr><td><a href="profile.php?username=kissaye"</a>kissaye</td>
<td>20</td>
<td>shreiwekh</td>
<td>2014-03-03 14:34:59</td>
</tr> <tr class="alt"><td><a href="profile.php?username=maas12345"</a>maas12345</td>
<td>7</td>
<td>maas12345</td>
<td>2014-02-13 20:23:56</td>
</tr> <tr><td><a href="profile.php?username=maas123456"</a>maas123456</td>
<td>8</td>
<td>maas123456</td>
<td>2014-02-13 20:25:51</td>
</tr> <tr class="alt"><td><a href="profile.php?username=marly"</a>marly</td>
<td>9</td>
<td>Marly Mario</td>
<td>2014-02-19 22:02:50</td>
</tr> <tr><td><a href="profile.php?username=mohamad"</a>mohamad</td>
<td>10</td>
<td>mohamad salem</td>
<td>2014-02-19 22:27:48</td>
</tr> <tr class="alt"><td><a href="profile.php?username=rami1234"</a>rami1234</td>
<td>6</td>
<td>rami1234</td>
<td>2014-02-13 20:21:48</td>
</tr> <tr><td><a href="profile.php?username=ramizmo"</a>ramizmo</td>
<td>25</td>
<td>ramy om</td>
<td>2014-03-06 03:26:52</td>
</tr> <tr class="alt"><td><a href="profile.php?username=saeed"</a>saeed</td>
<td>16</td>
<td>Saeed Shaweesh</td>
<td>2014-02-28 21:59:37</td>
</tr> <tr><td><a href="profile.php?username=sheeerokh"</a>sheeerokh</td>
<td>21</td>
<td>sheeerokh mo7sen</td>
<td>2014-03-03 14:43:45</td>
</tr> <tr class="alt"><td><a href="profile.php?username=sheeerokh22"</a>sheeerokh22</td>
<td>22</td>
<td>sheeerokh mo7sen22</td>
<td>2014-03-03 14:45:50</td>
</tr> <tr><td><a href="profile.php?username=shinyor"</a>shinyor</td>
<td>23</td>
<td>shinyor kalb</td>
<td>2014-03-03 14:47:40</td>
</tr></table>';
when i run strip_tags i only get the four table head parts but not the rest of the table. what am i doing wrong please? this is what i get:
Pt. usernamePt. numberFull NameAdded on
You have just to close the bracket for example.
<a href="profile.php?username=fringo123"</a>fringo123
to
fringo123
etc.

php mysql - get more than 1 record in single query

I have a table like
<table width="60%" border="0">
<tr>
<td>intId</td>
<td>tagname</td>
<td>cid</td>
<td>lid</td>
</tr>
<tr>
<td>1</td>
<td>chemis</td>
<td>5</td>
<td>0</td>
</tr>
<tr>
<td>2</td>
<td>hist</td>
<td>4</td>
<td>0</td>
</tr>
<tr>
<td>3</td>
<td>canada</td>
<td>0</td>
<td>9</td>
</tr>
<tr>
<td>4</td>
<td>chemis</td>
<td>6</td>
<td>0</td>
</tr>
<tr>
<td>5</td>
<td>chemis</td>
<td>9</td>
<td>2</td>
</tr>
<tr>
<td>6</td>
<td>hist</td>
<td>3</td>
<td>1</td>
</tr>
</table>
$srarchkey_arr = array('chemis','tes','loyal','hist','canada');
My output should be
<table width="60%" border="0">
<tr>
<td>Tag Name </td>
<td>cid</td>
<td>lid</td>
</tr>
<tr>
<td>Chemis</td>
<td>5,6,9</td>
<td>0,0,2</td>
</tr>
<tr>
<td>hist</td>
<td>4,3,</td>
<td>0,1</td>
</tr>
<tr>
<td>canada</td>
<td>0</td>
<td>9</td>
</tr>
</table>
Please refer the fiddle
i.e In my tags table i have lots of tags with cid and lid
I want to search the words which are in array $srarchkey_arr. I want to search these tags and give the output as specified. I used the like query but it gives the out put as individual record. So i again use loops to concat the cid and lids.
Is this possible to do this with single query and loop. Is there any possibility to pass this like array or like in() for strings.
Please help me. thanks
use this sql
SELECT tagname, group_concat(cid), group_concat(lid) from test.check group by tagname;

Categories