Time Banding with Mysql time datatype - php

i wish to query my sales table and get the count of distinct receipt numbers
by hour for each day of the week
each record has a receipt number that does repeat, a datein in field that is just date data type, and a sepearte time field in the time datatype
here is the query i'm trying to use
select dayname(datein),dayofweek(datein),
if(hour(timein) between 9 and 11, count(distinct salenbr),0) as `9-11`,
if(hour(timein) between 11 and 13, count(distinct salenbr),0) as `11-13`,
if(hour(timein) between 13 and 15, count(distinct salenbr),0) as `13-15`,
if(hour(timein) between 15 and 17, count(distinct salenbr),0) as `15-17`,
if(hour(timein) between 17 and 19, count(distinct salenbr),0) as `17-19`,
if(hour(timein) between 19 and 21, count(distinct salenbr),0) as `19-21`
from carmanslive.allsales
where loccode = 'SF' and exitcode in ('64','65')
and deptname = 'Photofinishing'
and datein >= DATE_SUB(NOW(), INTERVAL 3 MONTH)
group by dayname(datein),dayofweek(datein)
order by dayofweek(datein)
the output is wrong though
<table caption="UnknownTable (7 rows)">
<thead>
<tr>
<th class="col0">dayname(datein)</th>
<th class="col1">dayofweek(datein)</th>
<th class="col2">9-11</th>
<th class="col3">11-13</th>
<th class="col4">13-15</th>
<th class="col5">15-17</th>
<th class="col6">17-19</th>
<th class="col7">19-21</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col0">Sunday</td>
<td class="col1">1</td>
<td class="col2">0</td>
<td class="col3">118</td>
<td class="col4">0</td>
<td class="col5">0</td>
<td class="col6">0</td>
<td class="col7">0</td>
</tr>
<tr>
<td class="col0">Monday</td>
<td class="col1">2</td>
<td class="col2">0</td>
<td class="col3">0</td>
<td class="col4">360</td>
<td class="col5">360</td>
<td class="col6">0</td>
<td class="col7">0</td>
</tr>
<tr>
<td class="col0">Tuesday</td>
<td class="col1">3</td>
<td class="col2">0</td>
<td class="col3">390</td>
<td class="col4">0</td>
<td class="col5">0</td>
<td class="col6">0</td>
<td class="col7">0</td>
</tr>
<tr>
<td class="col0">Wednesday</td>
<td class="col1">4</td>
<td class="col2">480</td>
<td class="col3">0</td>
<td class="col4">0</td>
<td class="col5">0</td>
<td class="col6">0</td>
<td class="col7">0</td>
</tr>
<tr>
<td class="col0">Thursday</td>
<td class="col1">5</td>
<td class="col2">0</td>
<td class="col3">0</td>
<td class="col4">0</td>
<td class="col5">330</td>
<td class="col6">0</td>
<td class="col7">0</td>
</tr>
<tr>
<td class="col0">Friday</td>
<td class="col1">6</td>
<td class="col2">0</td>
<td class="col3">380</td>
<td class="col4">380</td>
<td class="col5">0</td>
<td class="col6">0</td>
<td class="col7">0</td>
</tr>
<tr>
<td class="col0">Saturday</td>
<td class="col1">7</td>
<td class="col2">0</td>
<td class="col3">0</td>
<td class="col4">368</td>
<td class="col5">0</td>
<td class="col6">0</td>
<td class="col7">0</td>
</tr>
</tbody>
</table>
there should be data in each column, i've confirmed the data is there.

I assume you have to put the aggregate around your if. Something like:
select dayname(datein),dayofweek(datein),
count(distinct if(hour(timein) between 9 and 11, salenbr,0)) as `9-11`
[...]

Related

Set While loop in FPDF

This is code is using to generate pdf file. I using $html to do the table and will display in pdf file. But now if insert the while loop in the $html, the output is the php code and got some error. I confusing the single quotes to closing the code.
$html='<br><br><br>
<table border="1">
<tr>
<td bgcolor="#D0D0FF">Product Name</td>
<td bgcolor="#D0D0FF">Product Price</td>
<td bgcolor="#D0D0FF">Product Quantity</td>
<td bgcolor="#D0D0FF">Total Price</td>
</tr>
//Here
</table>`
<br>
<table border="1">
<tr>
<td bgcolor="#D0D0FF">Order Date</td>
<td width="600">'.$row['Order_Date'].'</td>
</tr>
<tr>
<td bgcolor="#D0D0FF">Tracking ID</td>
<td width="600">'.$row['Tracking_ID'].'</td>
</tr>
<tr>
<td bgcolor="#D0D0FF">Recipient</td>
<td width="600">'.$row['Tracking_Recipient'].'</td>
</tr>
<tr>
<td bgcolor="#D0D0FF">Phone Number</td>
<td width="600">'.$row['Tracking_PhoneNumber'].'</td>
</tr>
<tr>
<td bgcolor="#D0D0FF">Address</td>
<td width="600">'.$row['Tracking_Address'].'</td>
</tr>
<tr>
<td bgcolor="#D0D0FF">Bank</td>
<td width="600">'.$row['Bank'].'</td>
</tr>
</table>';
//While loop

How to get data and set in to php var when use file_get_contents PHP?

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.

Multiple Checkbox Update and Delete Query

I want to update tutor table and tutor course table, i have multiple checkbox for tutor course and if a teacher update his course or other info both table should also update.... tutor can increase or decrease course. I'm using following query but its not working for me
$update_content = mysql_query("UPDATE wp_tutor
JOIN wp_tutor_courses
ON wp_tutor.tutor_id=wp_tutor_courses.tutor_id
SET wp_tutor.tutor_name='$tNameVar',
wp_tutor.tutor_qualification='$tQualVar',
wp_tutor.tutor_skype='$tSkyVar',
wp_tutor.tutor_specialization='$tuSAreaVar',
wp_tutor.tutor_gender='$tuGenderVar',
wp_tutor_courses.course_id='$tuCourseVar'
WHERE tutor_id='$tid'");
<table cellpadding="5" cellspacing="0" border="1">
<caption>Tutor Table</caption>
<thead>
<tr>
<th>Tutor ID</th>
<th>Tutor Name</th>
<th>Tutor Skype ID</th>
<th>Tutor Specialization</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">1</td>
<td align="center">Kashif</td>
<td align="center">kashiflatif</td>
<td align="center">Financial Accounting</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">Ammar</td>
<td align="center">ammar.90</td>
<td align="center">Research Methods</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">Bilal</td>
<td align="center">bilalhaider95</td>
<td align="center">Islamic Bond & Practices</td>
</tr>
</tbody>
</table>
<br />
<br />
<table cellpadding="5" cellspacing="0" border="1" style="float:left">
<caption>Tutor Course Table</caption>
<thead>
<tr>
<th>Tutor Course ID</th>
<th>Tutor ID</th>
<th>Course ID</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">1</td>
<td align="center">2</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">1</td>
<td align="center">3</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">2</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">5</td>
<td align="center">2</td>
<td align="center">3</td>
</tr>
<tr>
<td align="center">6</td>
<td align="center">3</td>
<td align="center">1</td>
</tr>
</tbody>
</table>
<table cellpadding="5" cellspacing="0" border="1" style="float:left; margin-left:20px;">
<caption>Course Table</caption>
<thead>
<tr>
<th>Course ID</th>
<th>Course Name</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">1</td>
<td align="center">Certificate</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">Diploma</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">PGD</td>
</tr>
</tbody>
</table>
Try this:
$update_content = mysql_query("UPDATE wp_tutor a
INNER JOIN wp_tutor_courses b
ON a.tutor_id=b.tutor_id
SET a.tutor_name='$tNameVar',
a.tutor_qualification='$tQualVar',
a.tutor_skype='$tSkyVar',
a.tutor_specialization='$tuSAreaVar',
a.tutor_gender='$tuGenderVar',
b.course_id='$tuCourseVar'
WHERE a.tutor_id='$tid'");

PHP How can I show total data based on Department

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.

How do I extract values from a html page stored as string using curl function

I am using PHP / curl to get a HTML into a string and then i need to extract the following data and then project a graph out of it .
The data I want looks like :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" />
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<td>
<h3>Income</h3>
</td>
</tr>
<tr>
<td>Operating income</td>
<td class="numericalColumn">22,922.00</td>
<td class="numericalColumn">21,507.30</td>
<td class="numericalColumn">17,492.60</td>
<td class="numericalColumn">13,683.90</td>
<td class="numericalColumn">10,227.12</td>
</tr>
<tr>
<td>
<h3>Expenses</h3>
</td>
</tr>
<tr>
<td>Material consumed</td>
<td class="numericalColumn">4,029.40</td>
<td class="numericalColumn">3,442.60</td>
<td class="numericalColumn">2,952.30</td>
<td class="numericalColumn">1,889.00</td>
<td class="numericalColumn">1,367.67</td>
</tr>
<tr>
<td>Manufacturing expenses </td>
<td class="numericalColumn">2,213.20</td>
<td class="numericalColumn">1,841.80</td>
<td class="numericalColumn">299.80</td>
<td class="numericalColumn">120.50</td>
<td class="numericalColumn">1,020.70</td>
</tr>
<tr>
<td>Personnel expenses</td>
<td class="numericalColumn">9,062.80</td>
<td class="numericalColumn">9,249.80</td>
<td class="numericalColumn">7,409.10</td>
<td class="numericalColumn">5,768.20</td>
<td class="numericalColumn">4,279.03</td>
</tr>
<tr>
<td>Selling expenses</td>
<td class="numericalColumn">378.10</td>
<td class="numericalColumn">308.40</td>
<td class="numericalColumn">532.10</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">171.05</td>
</tr>
<tr>
<td>Adminstrative expenses</td>
<td class="numericalColumn">1,737.00</td>
<td class="numericalColumn">1,906.00</td>
<td class="numericalColumn">2,583.70</td>
<td class="numericalColumn">2,651.70</td>
<td class="numericalColumn">904.78</td>
</tr>
<tr>
<td>Expenses capitalised</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
</tr>
<tr>
<td>Cost of sales</td>
<td class="numericalColumn">17,420.50</td>
<td class="numericalColumn">16,748.60</td>
<td class="numericalColumn">13,777.00</td>
<td class="numericalColumn">10,429.40</td>
<td class="numericalColumn">7,743.22</td>
</tr>
<tr>
<td>Operating profit</td>
<td class="numericalColumn">5,501.50</td>
<td class="numericalColumn">4,758.70</td>
<td class="numericalColumn">3,715.60</td>
<td class="numericalColumn">3,254.50</td>
<td class="numericalColumn">2,483.90</td>
</tr>
<tr>
<td>Other recurring income</td>
<td class="numericalColumn">434.20</td>
<td class="numericalColumn">468.20</td>
<td class="numericalColumn">326.90</td>
<td class="numericalColumn">288.70</td>
<td class="numericalColumn">113.59</td>
</tr>
<tr>
<td>Adjusted PBDIT</td>
<td class="numericalColumn">5,935.70</td>
<td class="numericalColumn">5,226.90</td>
<td class="numericalColumn">4,042.50</td>
<td class="numericalColumn">3,543.20</td>
<td class="numericalColumn">2,597.49</td>
</tr>
<tr>
<td>Financial expenses</td>
<td class="numericalColumn">108.40</td>
<td class="numericalColumn">196.80</td>
<td class="numericalColumn">116.80</td>
<td class="numericalColumn">7.20</td>
<td class="numericalColumn">3.13</td>
</tr>
<tr>
<td>Depreciation </td>
<td class="numericalColumn">579.60</td>
<td class="numericalColumn">533.60</td>
<td class="numericalColumn">456.00</td>
<td class="numericalColumn">359.80</td>
<td class="numericalColumn">292.26</td>
</tr>
<tr>
<td>Other write offs</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
</tr>
<tr>
<td>Adjusted PBT</td>
<td class="numericalColumn">5,247.70</td>
<td class="numericalColumn">4,496.50</td>
<td class="numericalColumn">3,469.70</td>
<td class="numericalColumn">3,176.20</td>
<td class="numericalColumn">2,302.10</td>
</tr>
<tr>
<td>Tax charges </td>
<td class="numericalColumn">790.80</td>
<td class="numericalColumn">574.10</td>
<td class="numericalColumn">406.40</td>
<td class="numericalColumn">334.10</td>
<td class="numericalColumn">286.10</td>
</tr>
<tr>
<td>Adjusted PAT</td>
<td class="numericalColumn">4,456.90</td>
<td class="numericalColumn">3,922.40</td>
<td class="numericalColumn">3,063.30</td>
<td class="numericalColumn">2,842.10</td>
<td class="numericalColumn">2,016.00</td>
</tr>
<tr>
<td>Non recurring items</td>
<td class="numericalColumn">441.10</td>
<td class="numericalColumn">-948.60</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">38.33</td>
</tr>
<tr>
<td>Other non cash adjustments</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-33.85</td>
</tr>
<tr>
<td>Reported net profit</td>
<td class="numericalColumn">4,898.00</td>
<td class="numericalColumn">2,973.80</td>
<td class="numericalColumn">3,063.30</td>
<td class="numericalColumn">2,842.10</td>
<td class="numericalColumn">2,020.48</td>
</tr>
<tr>
<td>Earnigs before appropriation</td>
<td class="numericalColumn">4,898.00</td>
<td class="numericalColumn">2,973.80</td>
<td class="numericalColumn">3,063.30</td>
<td class="numericalColumn">2,842.10</td>
<td class="numericalColumn">2,020.48</td>
</tr>
<tr>
<td>Equity dividend</td>
<td class="numericalColumn">880.90</td>
<td class="numericalColumn">586.00</td>
<td class="numericalColumn">876.50</td>
<td class="numericalColumn">873.70</td>
<td class="numericalColumn">712.88</td>
</tr>
<tr>
<td>Preference dividend</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
</tr>
<tr>
<td>Dividend tax</td>
<td class="numericalColumn">128.30</td>
<td class="numericalColumn">99.60</td>
<td class="numericalColumn">148.90</td>
<td class="numericalColumn">126.80</td>
<td class="numericalColumn">99.98</td>
</tr>
<tr>
<td>Retained earnings</td>
<td class="numericalColumn">3,888.80</td>
<td class="numericalColumn">2,288.20</td>
<td class="numericalColumn">2,037.90</td>
<td class="numericalColumn">1,841.60</td>
<td class="numericalColumn">1,207.62</td>
</tr>
</tbody>
</table>
</body>
</html>
I want to extract each value like Manufacturing Data and the values of all the years mentioned in that line. How do I go about this?
I found something like preg_match('#<tr><th>(.*)</th> <td><b>price</b></td></tr>#', $content, $match); but that doesn't get the values I want.
If i understood you question well you want something like this to be done. this was written by me so if you need clarifications i'd love to help.
cheers !
You can use libraries like PHP Simple HTML DOM Parser to extract data from HTML/XHTML.
http://simplehtmldom.sourceforge.net/manual.htm
An example:
$pageDom = str_get_html( $rawHtmlData );
foreach( $pageDom->find( 'td' ) as $tblElem )
{
if( FALSE !== stristr( $tblElem->innertext, 'Manufacturing expenses' ) )
{
// Do stuff
}
}

Categories