I have a code below :
<table>
<th class="th1">OT Date</th>
<td class="td1"><?php echo $date?></td>
<tr>
<th class="th" colspan="7">Department</th>
<tr>
<td class="td1" style="width: 100px;">Accounting</td>
<td class="td1" style="width: 100px;">Admin</td>
<td class="td1" style="width: 100px;">Facility</td>
<td class="td1" style="width: 100px;">IQC</td>
<td class="td1" style="width: 100px;">PC</td>
<td class="td1" style="width: 100px;">Production</td>
<td class="td1" style="width: 100px;">Store</td>
<tr>
<td class="td">20</td>
<td class="td">20</td>
<td class="td">20</td>
<td class="td">20</td>
<td class="td">20</td>
<td class="td">20</td>
<td class="td">20</td>
</table>
I plan to show total data based on Department. So in table example Admin, will automatically total the data.
and this is the php function code :
<?php
include ("config.php");
$dept="Admin";
$pesan = mysql_query("SELECT submission_no FROM t_submissions WHERE dept_name='$dept'");
$j = mysql_num_rows($pesan);
if($j>0)
{
echo $j;
}
else
{
echo "no data";
}?>
How can I set it if dept=Admin, then it will update total data to admin table, if dept=Accounting, it will update it too and so on.
You can use GROUP BY with aggregate functions in your MySQL query to add or otherwise organize the data by department and then display it in your webpage:
SELECT SUM(column_name) FROM t_submissions GROUP BY dept_name;
Obviously you will change the query according to your needs.
Related
How to get data and set in to php var when use file_get_contents PHP ?
this is code for http://www.example.com/test.php
<table align="center">
<thead style="background-color: #F0F0F0; color: #333333; text-align: center;">
<tr>
<th class="countryHeader">Country</th>
<th class="intHeader"> </th>
<th colspan="2" class="intHeader">Desktop CPM</th>
<th colspan="2" class="bannerHeader">Mobile CPM</th>
</tr>
</thead>
<tbody>
<tr class="breaker">
<td> </td>
<td>Highest</td>
<td>Unique</td>
<td>Raw</td>
<td>Unique</td>
<td>Raw</td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United States</td>
<td class="cpmRaw">$2.00</td>
<td class="cpm">$3.44</td>
<td class="cpmRaw">$2.00</td>
<td class="cpmMobile">$1.63</td>
<td class="cpmMobileRaw">$0.97</td>
</tr>
<tr class="even rateVals">
<td class="countryName">Canada</td>
<td class="cpmRaw">$1.20</td>
<td class="cpm">$2.52</td>
<td class="cpmRaw">$1.20</td>
<td class="cpmMobile">$1.88</td>
<td class="cpmMobileRaw">$1.06</td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United Kingdom</td>
<td class="cpmRaw">$1.60</td>
<td class="cpm">$2.10</td>
<td class="cpmRaw">$1.08</td>
<td class="cpmMobile">$1.71</td>
<td class="cpmMobileRaw">$0.94</td>
</tr>
<tr class="even rateVals">
<td class="countryName">Australia</td>
<td class="cpmRaw">$1.50</td>
<td class="cpm">$2.62</td>
<td class="cpmRaw">$1.20</td>
<td class="cpmMobile">$2.73</td>
<td class="cpmMobileRaw">$1.49</td>
</tr>
<tr class="breaker">
<td colspan="6"> </td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United Arab Emirates</td>
<td class="cpmRaw">$1.48</td>
<td class="cpm">$2.49</td>
<td class="cpmRaw">$1.45</td>
<td class="cpmMobile">$2.11</td>
<td class="cpmMobileRaw">$1.42</td>
</tr>
<tr class="odd rateVals">
<td>All other countries</td>
<td>-</td>
<td colspan="2">$0.25 - $2.00</td>
<td colspan="2">$0.06 - $0.22</td>
</tr>
</tbody>
</table>
And this is code for my_code.php
<?php
$test = file_get_contents('http://www.example.com/test.php');
//echo $test;
?>
And i want to get php var from column Mobile CPM raw value like this
$United_States = "0.97";
$Canada = "1.07";
$United_Kingdom = "0.94";
$Australia = "1.49";
$United_Arab_Emirates = "1.42";
How can i do ?
If you want to parse a HTML document you should use PHP's DOMDocument. Instead of file_get_contents() you should use loadHTMLFile(). Because you are using CSS-classes you should view this post on how to find elements via class.
I have the way to get the value of the td's at the time the row is selected using
$(this).find('.servid').val()
However I cannot find the way to get this value later.
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
I need to later, after filling out more of the form, get the val() of the selected tr -> servid td
I have tried various things but they are not working
$('#servicetable .selected > td:nth-child(2)').val();
$('#servicetable').find('.selected > td:nth-child(2)').val();
$('#servicetable').find('tr.selected').find('.servid').val();
Below goes your sollution
alert($('#servicetable tr.selected > td.servid').attr('value'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
One more thing you can not put value like this as it will not validate as per w3c, recommanded to put data-value, if HTML5.
And in jquery also you can put like
alert($('#servicetable tr.selected > td.servid').attr('data-value'));
$('#value1').text($('#servicetable .selected > td:nth-child(2)').attr('value'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
<label id="value1"/>
IDEAL WAY
use data attribute as shown below,
<td class="servid" data-value="4004072">72569000</td>
$('#value1').text($('#servicetable .selected > td:nth- child(2)').data('value'));
It might be better if you tag the TR with the id you need and then have the "attributes" in the TDs.
You can then parse TDs based on TR
<tr class="selected" id="98989">
<td class="city">Lisbon</td>
.....
_tr = $("#servicetable .selected");
_trId=_tr.attr("id");
_trCity = _tr.find(".city").text();
.....
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 have a page contains a table and this table contains a lot of coding like this
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
<? $res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){ ?>
<tr style="width:700px">
<td class="tabletext"><?= ++$serial;?></td>
<td class="tabletext" ><?= $resArr[stName];?></td>
<td class="tabletext"><?= $resArr['date'];?></td>
<td class="tabletext" ><?= $resArr[matName];?></td>
<td class="tabletext" ><? if($resArr[exam]==1) echo "work";else echo "final";?></td>
<td class="tabletext" ><? if($resArr[exam_type]==1) echo "prac";else echo "test";?></td>
</tr>
<? }?>
</tbody>
</table>
as you see the table has php coding
now i want to store the whole table in variable so i can send it to pdf printing library tcpdf
You can use heredoc syntax, but you need to move the conditionals outside:
<?php
if($resArr['exam']==1) $exam = "work"; else $exam = "final";
if($resArr["exam_type"]==1) $examtype = "prac";else $examtype = "test";
$var = <<<EOT
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
$res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){
<tr style="width:700px">
<td class="tabletext">{++$serial}</td>
<td class="tabletext" >{$resArr["stName"]}</td>
<td class="tabletext">{$resArr["date"]}</td>
<td class="tabletext" >{$resArr["matName"]}</td>
<td class="tabletext" >{$exam}</td>
<td class="tabletext" >{$examtype}</td>
</tr>
<? }?>
</tbody>
</table>
EOT;
echo $var;
Another way, if you already have all of this code and want to save it:
Before the table:
<?php ob_start(); ?>
After the table:
<?php $output = ob_get_contents(); ?>
The table will still be displayed and you can use $output to send to the PDF.
I m working on module in which i have to make pdf from php page. I m Using tcpdf for that but m facing one problem that file contain some mysql queries and php coding which is not executed by pdf page.
$prn_no = $_POST['prn_no'];
$current_sem = $_POST['current_sem'];
$qr_fetch_sem_res_id = mysql_query("SELECT * FROM table1 WHERE ((prn='$prn_no') AND (semisterName='$current_sem'))")or die(mysql_error());
$qr_fetch_sem_result_ans = mysql_fetch_array($qr_fetch_sem_res_id);
<tr>
<td colspan="11" align="left" valign="middle">Programme Name: <?php echo $qr_fetch_sem_result_ans['programme_name'];?></td>
</tr>
<tr>
<td colspan="11" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="27%">Seat No.: <?php echo $qr_fetch_sem_result_ans['seatNo'];?></td>
<td width="3%"> </td>
<td width="22%">PR No. : <?php echo $qr_fetch_sem_result_ans['prn'];?></td>
<td width="2%"> </td>
<td width="17%">Semester : <?php echo $qr_fetch_sem_result_ans['semisterName'];?></td>
<td width="1%"> </td>
<td width="25%">Month / Year Of Exam : <?php echo $qr_fetch_sem_result_ans['month_year_of_exam'];?> </td>
<td width="3%"> </td>
</tr>
<tr>
<td colspan="3">Name: <?php echo $qr_fetch_sem_result_ans['student_name'];?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="7">College / Institute: <?php echo $qr_fetch_sem_result_ans['institute_name'];?></td>
<td> </td>
</tr>
</table></td>
</tr>
I'm going to go out on a limb here and suggest that you run your queries fist and then build your pdf file. If you run the queries after you build the pdf then of course it will not have access to your data. If that doesn't help then I must not understand what you're asking.