DataTables putting tables inside of a datatable - php

I need to put tables in my datatable, but it doesn't look like datatables likes it. Does anyone know how I can get the functionality I need? I tried putting in divs that look like tables instead of tables, but it still broke. I think because the tr only has one td.
My code:
foreach($campaigns as $campaign):?>
<tr>
<td><?php echo $campaign['name']?></td>
<td><?php echo date('m/d/Y', strtotime($campaign['created_date']))?></td>
<td><?php echo $campaign['country_id']?></td>
<td><?php echo $campaign['domain_getter_type']?></td>
<td><?php echo $campaign['domain_metrics']?> <?php echo $campaign['metric_filter_setting_id']?></td>
<td><?php echo $campaign['domain_contact']?></td>
<td>0</td>
</tr>
<!--campaign runs-->
<tr>
<td colspan="99">
<table>
<thead>
<tr>
<th>dfad</th>
<th>t3wtaw3 On</th>
<th>dfw</th>
<th>Domain dawfd</th>
<th>p3p3</th>
</tr>
</thead>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
</td>
</tr>
<?php endforeach;?>
After each row of data, I want to put a hidden table you can show or hide, that holds additional information about each specific run of that campaign.
I get this error in chrome: Uncaught TypeError: Cannot read property 'className' of undefined

Assuming this question is referring to the jQuery DataTables JavaScript plugin (assuming because I see no mention of JS in the example code provided), I would follow the author's example that he outlines in his blog here: http://datatables.net/blog/Drill-down_rows
I have used this method before and it works quite well.
It does assume that you are initializing the table as empty when it renders and then fetches the data with AJAX, but I see no reason it could not be easily modified to be generated server side.
Another option would be using the master / detail example as a guide, you can find that here along with the sample code: http://datatables.net/examples/api/row_details.html

Related

TCPDF not printing table rows containing colspan?

I am trying to print this table in TCPDF, the table is rendering fine but it is totally skipping the <tr> row with colspan , this happens to the only row that has the first <td colspan="8"> cell with a colspan.
This is the html table tha:
<table style="font-size:7px;line-height:16px;border:none;" dir="ltr" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:17%;"></td>
<td>YTD</td>
<td>2019</td>
<td>2018</td>
<td>2017</td>
<td>2016</td>
<td>2015</td>
<td>2014</td>
</tr>
<tr>
<td>Portfolio</td>
<td>-3.63%</td>
<td>14.51%</td>
<td>-5.11%</td>
<td>11.16%</td>
<td>8.48%</td>
<td>-2.13%</td>
<td>2.45%</td>
</tr>
<tr>
<td>Benchmark </td>
<td>-1.64%</td>
<td>9.78%</td>
<td>-3.84%</td>
<td>7.37%</td>
<td>2.92%</td>
<td>-2.66%</td>
<td>0.08%</td>
</tr>
<tr>
<td colspan="8">Morningstar USD Cautious Allocation</td>
</tr>
<tr>
<td></td>
<td>
<p class="double-line">Annualised Return</p>
</td>
<td>
<p class="double-line">Standard Deviation</p>
</td>
<td>
<p class="double-line">Sharpe Ratio</p>
</td>
<td colspan="4"></td>
</tr>
<tr>
<td>Portfolio</td>
<td>4.45%</td>
<td>5.72%</td>
<td>0.78</td>
<td colspan="4"></td>
</tr>
<tr>
<td>Benchmark </td>
<td>2.08%</td>
<td>2.44%</td>
<td>0.85</td>
<td colspan="4"></td>
</tr>
</tbody>
</table>
output on the browser page is fine (see image)
but output on the PDF removes that row completely:
The issue is solved, the problem was not in TCPDF, It was the table not having a proper closing tag for the row </tr> . The table above was coming from a custom field storing it in the DB of a wordpress site. Since the html is generated through a php code I had minor coding error that I forgot to close the row with </tr>. However when viewing the html content in a wordpress WYSWIG editor , it adds the self closing tags. When you debugging it on the browser page also most browsers add auto closing tags. These made me think that the html structure of the table is good and should be an issue with TCPDF. After checking the HTML in the database I finally figured out the table row wasn't closing properly.
Hopefully this will help someone having a similar issue in the future.

Get a blank sign in Twig Template for generating a PDF with PHPBundle

I want a required blank in the twig template of PHPPdf PDFBundle in Symfony2. But the HTML Tag don't work here. For example I want a simple table with a blank in each cell:
<pdf>
<dynamic-page>
<table>
<tr>
<td>Line 1</td>
<td>Line 2</td>
</tr>
<tr>
<td>In next cell the blank</td>
<td> </td>
</tr>
</table>
</dynamic-page>
</pdf>
But how I write before, the code is not allowed from the template. How can I get it on another way. And only to write a blank is not possible for each situation.
I found a solution. It works when I use the unicode for a blank
<pdf>
<dynamic-page>
<table>
<tr>
<td>Line 1</td>
<td>Line 2</td>
</tr>
<tr>
<td>In next cell the blank</td>
<td> </td>
</tr>
</table>
</dynamic-page>
</pdf>

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;

How to display filled information of appended row in another page? [duplicate]

This question already has answers here:
why the appended row's data didn't displayed after being submitted?
(2 answers)
Closed 9 years ago.
This page got a button ADD to append the row.Once the appended row is filled,when submit,it will connect/link to another page ,then the filled information will display at that page.But the problem is how to display the filled information of appended row on 2nd page had been done in 1st page by using PHP.(Sorry for my poor English and hope for understand).
<table width="600px" id="project">
<tr>
<td>1</td>
<td><textarea name="pro_1" cols="100" rows="2"></textarea></td>
</tr>
<tr>
<td>2</td>
<td><textarea name="pro_2" cols="100" rows="2"></textarea></td>
</tr>
<tr>
<td>3</td>
<td><textarea name="pro_3" cols="100" rows="2"></textarea></td>
</tr>
</table>
<input id="addbtn" type="button" name="addbtn" value="ADD">
Jquery script(for append the row):
$(document).ready(function() {
$("#addbtn").click(function(){
var num=parseInt($("#project tr:last").text());
num+=1;
$("#project").append("<tr><td>"+num+"</td><td><textarea cols='100' rows='2'></textarea></td></tr>");
});
PHP source code(for 2nd page):
<table width="600px" id="pub">
<tr>
<td>1</td>
<td><?php echo $_post["pro_1"]; ?></td>
</tr>
<tr>
<td>2</td>
<td><?php echo $_post["pro_2"]; ?></td>
</tr>
<tr>
<td>3</td>
<td><?php echo $_post["pro_3"]; ?></td>
</tr>
</table>
Give the dynamically-added textarea a name, then you following page will see it as a parameter & can render it back out in the HTML.
In the Javascript: (PLEASE don't try and munge all your code, on one line!):
$("#project").append("<tr>);
$("#project").append("<td>"+num);
$("#project").append("<td><textarea name='pro_"+num+"' cols='100' rows='2'></textarea>");
See how a pinch of readability, makes it comprehensible? I'm following the HTML spec that says </td> and </tr> are OPTIONAL, not mandatory -- I never emit them myself.
And in your PHP second page, you need to pick up the correct parameter name. (You're looking for pub_N, not pro_N which you appear to post under).
Tidy your code up, get your names right.
Then put a PHP loop around it, to render Project Names with ascending numbers until it runs out of parameters. My PHP code is rough, but..
<?php
$rowNum = 1;
while (true) {
$rowValue = $_post["pro_"+$rowNum];
if (! isset($rowValue))
break; // Reached the end.
?>
<tr>
<td><?= htmlentities( $rowValue) ?></td>
<?php
}
?>
Hope this helps!

PHP table creation with arrays

I have a table with a first column called: "Fruit", and a last column called: "Total"
And any columns in between are dynamically created by the number of students.
Below is what I'm looking to dynamically make, from what the database shows so far.
<table border="1">
<tr>
<th>Fruit</th>
<th>Sally</th>
<th>John</th>
<th>Total</th>
</tr>
<tr>
<td>apples</td>
<td>5</td>
<td>3</td>
<td>8</td>
</tr>
<tr>
<td>bananas</td>
<td>3</td>
<td>5</td>
<td>8</td>
</tr>
<tr>
<td>Oranges</td>
<td>3</td>
<td>3</td>
<td>6</td>
</tr>
<tr>
<td></td>
<td>11</td>
<td>11</td>
<td>22</td>
</tr>
</table>
Here's the difficulties I run into. The fruit names, students, and fruit consumed are pulled from the database.
And I don't know how many fruit rows nor student columns there will be.
This is as far as I got:
<table>
<tr>
<th>Fruit</th>
<?php $sqlS = db("SELECT s.*, sf.consumed FROM `tbl_students` s, `tbl_students_fruit` sf WHERE s.studentid = f.studentid ORDER BY s.studentname ASC");
while($student = mysql_fetch_array($sqlS)){ ?>
<th><?php echo $student['studentname'];?></th>
<?php } ?>
<th>Total</th>
</tr>
<?php $sqlF = db("SELECT * FROM `tbl_fruit` ORDER BY fruitname ASC");
while($fruit = mysql_fetch_array($sqlF)){ ?>
<tr>
<td><?php echo $fruit['fruitname'];?></th>
<td></td>
<td></td>
</tr>
<? } ?>
</table>
As you can see, I'm creating the Fruit rows, and Student columns. But it's incomplete. I've only created the column headers, and not the columns below the headers. From this point I am stuck on the guts of the table.
I am sure arrays are the way to go with this monstrosity. But the only way my feeble brain can make this work is to have more queries, which I'm sure is a very wrong way to do this.
If there were 3 students or 15 students, I can make them appear in the table th columns, but not in rows in their columns.
How does one traverse dynamic columns this way?
And if my demo above is confusing, I don't blame you!
well, I am assuming that your db structure is as follows:
[tbl_students]
studentid, studentname
[tbl_fruit]
fruitid, fruitname
[tbl_students_fruit]
id, fruitid, studentid, consumed
http://pastebin.com/CxPUeXR0
I haven't tested it, so good luck

Categories