I'm trying to figure out how to apply attributes to my table via php email. I can't get the background and and rowspan to work. Can't figure it out.
$to = 'XXXXX';
$subject = 'New Homeless Connection';
$msg = "<html>
<head>
<title>New Homeless Connection</title>
</head>
<body>
<table cellspacing=\"0\" cellpadding=\"10\" border=\"1\" align=\"left\">
<tr>
<td align=\"left\" width=\"150px\" background=\"#EEEEEE\">Registery No.:</td>
<td align=\"left\"> $reg</td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">First Name:</td>
<td align=\"left\">$first_name </td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Connection Date:</td>
<td align=\"left\"$>$connect_date</td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Probability:</td>
<td align=\"left\"$>$prob</td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Volunteer Name:</td>
<td align=\"left\"$><strong>$hv_name</strong></td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Volunteer Phone:</td>
<td align=\"left\"$><strong>$hv_phone</strong></td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Consent Form:</td>
<td align=\"left\"$>$consent</td>
</tr>
<tr>
<td align=\"left\" background=\"#eee\">Field Count:</td>
<td align=\"left\"$>$reg_count</td>
</tr>
<tr>
<td align=\"left\" rowspan=\"2\">http://wwww.41q.org/admin/</td>
</tr>
</table>
</body>
</html>
";
A few things about tables:
You don't use "px" to define the width/height. Should just be width="150"
The background attribute should be bgcolor, and it doesn't use #. Just set bgcolor="eeeeee"
Why do you have $'s like this? <td align=\"left\"$> . Those shouldn't be there.
The rowspan is OK, but it's not doing anything because there is no row below it. I'm not sure what you are trying to do with the rowspan.
rowspan should be colspan, as your table has two columns all the way down except for the last row (whose cell needs to span both columns).
Also, background should be bgcolor.
I've posted up a sample with the replacement here: http://jsfiddle.net/8ymMh/4/
The gridlines show the last cell spanning both columns and the background colours come through OK.
I freely admit to have taken onboard AndrewR's suggestion of removing the hash from in front of the colour name (eeeeee) so all credit to him for that.
Related
I want to print a section of a table if the data is available in JSON file for it. And if the data is not there and it shouldn't do anything.
So, far what I am doing is as below. Checking is the account_type is parent and then generate the table rows with corresponding data.
<?php
$str = file_get_contents('test.json');
$json = json_decode($str, true);
$parent= strtr('<tr>
<td colspan="2" style="color:#263a80;font-size:19px;padding-bottom:20px;padding-top:20px">Parent Information</td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">First Name</td>
<td>#fname</td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">Last Name</td>
<td>#lname</td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">Mobile Number</td>
<td>#mobile</td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">Email</td>
<td><a #email target="_blank" rel="noreferrer">#email</a></td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">Country</td>
<td>#country</td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">State</td>
<td>#state</td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">City</td>
<td>#city</td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">Postal Code</td>
<td>#pcode</td>
</tr>
<tr>
<td style="width:30%;font-weight:700;padding-bottom:10px">Full Home Address</td>
<td>#address</td>
</tr>', ["#fname"=>$json["json"]["register_session_1"]["first_name"],
"#lname"=>$json["json"]["register_session_1"]["last_name"],
"#mobile"=>$json["json"]["register_session_1"]["mobile"],
"#email"=>$json["json"]["register_session_1"]["email"],
"#country"=>$json["json"]["register_session_1"]["country"],
"#state"=>$json["json"]["register_session_1"]["state_online"],
"#city"=>$json["json"]["register_session_1"]["city"],
"#pcode"=>$json["json"]["register_session_1"]["postal_code"],
"#address"=>$json["json"]["register_session_1"]["address"]
]);
if ($json["json"]["register_session_1"]["account_type"]==="parent"){
echo $parent;
}
else {
echo "hahahah";
}
?>
Problem is that it printing the table data anyway. I don't know what I am doing wrong. The if-else condition is not working.
I have this code and I can't seem to figure out why. I have added this code in between the <table></table> tag.
I am trying to style a <tr id="options"> generated by a PHP foreach() with jQuery, but everything I've tried only selects the first one, leaving the others intact. What can I do this? Simple example:
CSS:
td {border:1px solid black}
TABLE:
<table>
<tr>
<td>DATE</td>
<td>EXAM TITLE</td>
<td>EXAM CODE</td>
</tr>
<tr>
<td>TODAY</td>
<td>RANDOM</td>
<td>123</td>
</tr>
<tr>
<td>BUTTON</td>
<td>BUTTON</td>
<td>BUTTON</td>
</tr>
<tr>
<td colspan=3 id="options">
</tr>
I have tried this jQuery code (among other):
$("table").find("#options").each(function(){
$(this).css("border","0px");
});
It only styles my first <td id="options">. How can I get all of them?
Sorry if it is a stupid question. Thanks for the help.
convert id to classlike:- <td class="options">..</td>
and then you can use(Use Either-one)
CSS (standered way):-
td.options {border:1px solid black}
Or jQuery(try to avoid as much as possible):-
$('.options').css("border","1px solid black"); // no need of each
Example (both at same time):-
$('.options').css("font-size","21px");
td.options {border:1px solid black}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="options">DATE</td>
<td class="options">EXAM TITLE</td>
<td class="options">EXAM CODE</td>
</tr>
<tr>
<td class="options">TODAY</td>
<td class="options">RANDOM</td>
<td class="options">123</td>
</tr>
<tr>
<td class="options">BUTTON</td>
<td class="options">BUTTON</td>
<td class="options">BUTTON</td>
</tr>
</table>
I try to create tcpdf using writeHTML like this $pdf->writeHTML($html, true, 0, false, 0); which $html value like code below
<table border="1">
<tr>
<td width="100%" colspan="4">
<table border="0">
<tr>
<td width="18%" style="border-right:0.01px">Test 1</td>
<td width="12%">Test 2</td>
<td width="20%">Test 3</td>
</tr>
<tr>
<td width="18%" style="border-right:0.01px">Test 4</td>
<td width="12%">Test 5</td>
<td width="20%">Test 6</td>
</tr>
</table>
</td>
</tr>
</table>
style="border-right:0.01px" or style="border-right:0.1px" or style="border-right:1px" provide same result of border width, how to make this right border smaller? because my result rigth border on Test 1 and Test 4 are biggest then outside border.
If you're a little more explicit in your border definition it'll work as you expect. TCPDF's HTML/CSS parser is rather limited so it helps to be as specific as possible with your styling rules and the like.
Your code should work with either border-right-width: 0.1px or with the rest of CSS properties for the shorthand of border-right, see the example HTML below and accompanying screenshot of a rendered PDF (zoomed to highlight difference)
<table border="1">
<tr>
<td width="100%" colspan="4">
<table border="0">
<tr>
<!-- This should work -->
<td width="18%" style="border-right-width:0.1px;">Test 1</td>
<td width="12%">Test 2</td>
<td width="20%">Test 3</td>
</tr>
<tr>
<!-- As should this -->
<td width="18%" style="border-right:0.1px solid black;">Test 4</td>
<td width="12%">Test 5</td>
<td width="20%">Test 6</td>
</tr>
<tr>
<!-- However, this does not. -->
<td width="18%" style="border-right:0.1px">Test Broken</td>
<td width="12%">Test :)</td>
<td width="20%">Test :)</td>
</tr>
</table>
</td>
</tr>
</table>
As you can see, it handles the first two definitions as expected with thinner borders.
I use style="border-right-color:white" to hidden right border
<td style="border-right-color:white; border-bottom-color:black; border-top-color:black"></td>
I have a Table, see Code. Its a table that has a table in it, so its nested. Now i want to get all vales of the parent table only and then all values of the child table.
To get the childs data i can do this:
$query = '//*[#id="WordClass"]/table[2]/tr/td[2]/table/tr';
$nodes = $xpath->query($query);
foreach ($nodes as $node) { //do more querys to get the td data and save it..
My problem is how to only get the data of the parent table without getting the child data/tr/td also.
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr valign="top">
<td>
<table cellpadding="1" cellspacing="2" border="0">
<tr>
<td class="colTitle" align="center" colspan="4">
Da Titel
</td>
</tr>
<tr>
<td class="colTitle" align="center" colspan="2">One
</td>
<td class="colTitle" align="center" colspan="2">Two
I
</td>
</tr>
<tr>
<td class="colSubTitle">Pe</td>
<td class="colSubTitle">Ve</td>
<td class="colSubTitle">Pe</td>
<td class="colSubTitle">Ve</td>
</tr>
<tr>
<td class="rowTitle">x</td>
<td class="colVerbDef">y</td>
<td class="rowTitle">z</td>
<td class="colVerbDef">c</td>
</tr>
<tr>
<td class="rowTitle">r</td>
<td class="colVerbDef">t</td>
<td class="rowTitle">z</td>
<td class="colVerbDef">z</td>
</tr>
</table>
</td>
<td>
<table cellpadding="1" cellspacing="2" border="0">
<tr>
<td class="colTitle" align="center" colspan="4">
Da Titel2
</td>
</tr>
<tr>
<td class="colTitle" align="center" colspan="2">One
</td>
<td class="colTitle" align="center" colspan="2">Two
I
</td>
</tr>
<tr>
<td class="colSubTitle">Pe2</td>
<td class="colSubTitle">Ve2</td>
<td class="colSubTitle">Pe2</td>
<td class="colSubTitle">Ve2</td>
</tr>
<tr>
<td class="rowTitle">x2</td>
<td class="colVerbDef">y2</td>
<td class="rowTitle">z2</td>
<td class="colVerbDef">c2</td>
</tr>
<tr>
<td class="rowTitle">r2</td>
<td class="colVerbDef">t2</td>
<td class="rowTitle">z2</td>
<td class="colVerbDef">z2</td>
</tr>
</table>
</td>
</tr>
</tbody>
You can get the contents of the parent table's td elements using a direct path from the root:
/table/tbody/tr/td
The contents of those cells happen to be another table element, but you can strip those out with DOMDocument.
To get the inner tables' td elements only excluding the parents, you can look for tables that have a td parent, then select its tds:
//td/table//td
If I've misunderstood your question, please feel free to explain further and I will update.
I am unable to find any post which has answer to my issue.
I have html file which has a table, need to convert this to a text file without losing the format USING php script, as it has to be printed as is on a dotmatrix printer.
OR if there is any other way of doing this, pl suggest !
The table is a Invoice format, pl see below:
<table width='100' height='300' border='0' cellspacing='0' cellpadding='1'> <tr> <td><img src='spacer.jpg' width='100' height='1'></td> <td><table width='840' border='1' cellspacing='2' cellpadding='0'><tr><td width='660' colspan='2' valign='top'><br><br><br><br><br><br><br><br><br>Customer Name: 3M India Ltd<br>
Address:Plat 48-51 Electronic City<br><br></td><td width='180' valign='top'><br><br><br><br><br><br><br><br><br>
Inv No: 78788<br><br>Date: 20/04/2012 12:28:18<br><br>
</td> </tr> <tr> <td width='292' valign='top'>DC Nos: 500, <br><br></td><td valign='top'> Your Order No.: 322<br>
C.E.Reg No.: <br>
Vehicle No.: KA-01-N-2345<br><td valign='top'> Party:<br>
TIN: 29400127541<br>
CST: 29400127541<br></td> </tr> <tr> <td colspan='2'>Sl No. Description Tariff Code Rate Qty </td> <td>Amount</td> </tr> <tr> <td colspan='3'> <table width='840' height='160' border='0' cellspacing='1' cellpadding='0'> <tr valign='top'> <td width='87'>1</td> <td width='247'>Argon</td> <td width='165'>AR1223</td> <td width='92'>120</td> <td width='67'>1 Nos</td> <td width='182'>120.00</td> </tr> </table> </td> </tr> <tr> <td colspan='2' valign='top'><div align='right'><br>VAT: 5.00 %<br>Demurrage: <br> Freight: <br><br> </div>Rupees Four Hundred & Fourty One Only.</td><td valign='top'><br> 21.00<br> 0.00<br> 300.00<br><br> </td> </tr> <tr> <td colspan='2' valign='top'><div align='right'>Total:<br><br>Rounded Off</div></td> <td valign='top'>441.00<br><br>441.00<br><br></td> </tr></table> </td> </tr></table>
Could you not open the HTML file in something like Microsoft Word and then send it to print?
You could also convert the HTML file to PDF, there's several free ones (Google "html to pdf conversion") as another option to see if it works.