another data date value null when grab html - php

here's my problem, i tried grab date and change to date format from special character in 2 table. it successful. but 1 table the date return 0000-00-00 00:00:00, another table success. here's code,table and output below.
Table 1
<TABLE class="tab1" border="1" cellpadding="0" cellspacing="0"
summary="">
<TR>
<TH align=left colspan=2 bgcolor=#0066CC><H1> Start RIP Job</H1>
</TH>
</TR>
<TR>
<TH align=left> Send Date:
</TH>
<TD class="td1" align=left> 1/9/2017 1:15 PM
</TD>
</TR>
<TR>
<TH align=left> RIP Start Date and Time:
</TH>
<TD class="td1" align=left> 13:21:22 09/01/2017
</TD>
</TR>
<TR>
<TH align=left> RIP End Date and Time:
</TH>
<TD class="td1" align=left> 13:21:33 09/01/2017
</TD>
</TR>
<TR>
<TH align=left> RIP Duration:
</TH>
<TD class="td1" align=left> 11 seconds
</TD>
</TR>
<TR>
<TH align=left colspan=2 bgcolor=#0066CC><H1> End RIP Job</H1>
</TH>
</TR>
</TABLE>
Table 2
<TABLE class="tab1" border="1" cellpadding="0" cellspacing="0"
summary="">
<TR>
<TH align=left colspan=2 bgcolor=#0066CC><H1> Start RIP Job</H1>
</TH>
</TR>
<TR>
<TH align=left> Printer:
</TH>
<TD class="td1" align=left> RunJiang Flora 3204P
</TD>
</TR>
<TR>
<TH align=left> Send Date:
</TH>
<TD class="td1" align=left> 9/29/2017 10:09 PM
</TD>
</TR>
<TR>
<TH align=left> RIP Start Date and Time:
</TH>
<TD class="td1" align=left> 22:09:49 29/09/2017
</TD>
</TR>
<TR>
<TH align=left> RIP End Date and Time:
</TH>
<TD class="td1" align=left> 22:10:13 29/09/2017
</TD>
</TR>
<TR>
<TH align=left> RIP Duration:
</TH>
<TD class="td1" align=left> 24 seconds
</TD>
</TR>
<TR>
<TH align=left colspan=2 bgcolor=#0066CC><H1> End RIP Job</H1>
</TH>
</TR>
</TABLE>
CODE :
$source=file_get_contents("C://xampp/htdocs/Champion/machine-logs/LogPrinting04/nulldate.HTML");
$dom = new DOMDocument();
$dom->loadHTML($source);
// print_r($dom);
$xp = new DOMXPath($dom);
$textList = $xp->query("//table[//th[contains(text(),'')]]");
foreach ( $textList as $text ) {
$enddate = $xp->evaluate(
"string(descendant::tr[th[contains(text(),'RIP End Date and Time') or contains(text(),'Output End Date And Time')]]/td/text())",
$text);
$date = preg_replace("/[^0-9a-zA-Z \/:\-]/", "", $enddate);
$xtime = strtotime($date);
$tes = date("Y-m-d H:i:s",$xtime);
echo "enddate=".$tes.PHP_EOL;
}
OUTPUT :
table 1 : 2017-09-01 13:21:33
table 2 : 0000-00-00 00:00:00

'29' is not a valid month value.
Look at the one that is returning a value. Notice that it's returning September 1, not January 9.
13:21:33 09/01/2017 -> 2017-09-01 13:21:33
mm dd yyyy yyyy mm dd
Then look at the one that is returning zeros.
22:10:13 29/09/2017
mm dd yyyy
29 is not a valid value for month. (If we're expecting this input to be a representation of September 29, then we're also probably expecting the first one to be a representation of January 1.)

Related

How to get a td value using SimpleHTMLDOM?

I have the following table which I'm trying to scrape with SimpleHtmlDom.
How would I reference/access the date value of "application received" and put it in to a variable. I've tried using the plain text approach, but this produces all the text in all of the td's.
<table id="simpleDetailsTable" summary="Case Details">
<tbody><tr>
<th scope="row" width="40%">
Reference
</th>
<td>
LA01/2018/0235/F
</td>
</tr>
<tr>
<th scope="row" width="40%">
Application Received
</th>
<td>
Fri 23 Feb 2018
<td>
</tr>
<tr>
<th scope="row" width="40%">
Address
</th>
<td>
206 Straid Road Bushmills.
</td>
</tr>
<tr>
<th scope="row" width="40%">
Proposal
</th>
<td>
Alterations to existing car showroom.
</td>
</tr>
<tr>
<th scope="row" width="40%">
Status
</th>
<td>
<span class="caseDetailsStatus">Application Received</span>
</td>
</tr>
<tr>
<th scope="row" width="40%">
Authority Decision
</th>
<td>
Not Available
</td>
</tr>
<tr>
<th scope="row" width="40%">
Authority Decision Date
</th>
<td>
Not Available
</td>
</tr>
<tr>
<th scope="row" width="40%">
PAC Decision
</th>
<td>
Not Available
</td>
</tr>
<tr>
<th scope="row" width="40%">
PAC Decision Date
</th>
<td>
Not Available
</td>
</tr>
</tbody></table>
Using the following code I'm able to echo out each listing.
curl_setopt($ch, CURLOPT_URL,$item);
$output = curl_exec($ch);
$html = str_get_html($output);
$table = $html->find('table',0);
$rowdata = array();
foreach($table->find('tr') as $row){
foreach($row->find('td') as $cell){
$listing = $cell->plaintext;
echo $listing,'<br>';
//echo '<pre>'; print_r($listing);echo'<pre/>';
}
}
which produces the following result;
LA01/2018/0254/O
Tue 27 Feb 2018
39 Lyttlesdale Garvagh.
Proposed new dwelling and proposed new paired access to include demolition of existing garage.
Application Received
Not Available
Not Available
Not Available
Not Available
LA10/2018/0265/F
Tue 27 Feb 2018
45 Glen Road Killyculla Tempo BT94 3JU
Replacement dwelling-amended position,house type (split level) and domestic garage from previous approval LA10/2017/0529/RM for same
Application Received
Not Available
Not Available
Not Available
Not Available
Can anyone put me right on what it is I should be doing?

PHP Xpath get both a href and text node

I have a table that contains a number of headings like this:
<TR>
<TH CLASS="ddtitle" scope="colgroup" >Linked text</TH>
</TR>
The table is thousands of lines long so I can't share in full, but here is the initial tag and one full item within the table. Sadly there is no nested wrapped around each item and the comments are mine - so it's a pain to decipher where one item begins and ends.
<TABLE CLASS="datadisplaytable" SUMMARY="Layout table" width="100%"><CAPTION class="captiontext">Items Found</CAPTION>
<!-- START of first item in the table -->
<TR>
<TH CLASS="ddtitle" scope="colgroup" >Linked text</TH>
</TR>
<TR>
<TD CLASS="dddefault">
<SPAN class="fieldlabeltext">Term: </SPAN>Fall
<BR>
<SPAN class="fieldlabeltext">Registration: </SPAN>Jan 1, 2018 to Aug 1, 2018
<BR>
<SPAN class="fieldlabeltext">Levels: </SPAN>Undergraduate
<BR>
<BR>
Location
<BR>
Lecture Schedule Type
<BR>
3.000 Credits
<BR>
View Entry
<BR>
<BR>
<TABLE CLASS="datadisplaytable" SUMMARY="Meeting time table"><CAPTION class="captiontext">Scheduled Meeting Times</CAPTION>
<TR>
<TH CLASS="ddheader" scope="col" >Type</TH>
<TH CLASS="ddheader" scope="col" >Time</TH>
<TH CLASS="ddheader" scope="col" >Days</TH>
<TH CLASS="ddheader" scope="col" >Where</TH>
<TH CLASS="ddheader" scope="col" >Date Range</TH>
<TH CLASS="ddheader" scope="col" >Schedule Type</TH>
<TH CLASS="ddheader" scope="col" >Instructors</TH>
</TR>
<TR>
<TD CLASS="dddefault">Lecture</TD>
<TD CLASS="dddefault">9:20 am - 10:10 am</TD>
<TD CLASS="dddefault">MWF</TD>
<TD CLASS="dddefault">Some Building Room 101</TD>
<TD CLASS="dddefault">Aug 1, 2018 - Dec 1, 2018</TD>
<TD CLASS="dddefault">Lecture</TD>
<TD CLASS="dddefault">Instructor Name (<ABBR title= "Primary">P</ABBR>)<A HREF="mailto:email#foo.com" target="Instructur Name" ><IMG SRC="/wtlgifs/email.png" ALIGN="middle" ALT="E-mail" CLASS="headerImg" TITLE="E-mail" NAME="web_email" HSPACE=0 VSPACE=0 BORDER=0 HEIGHT=16 WIDTH=16></A></TD>
</TR>
</TABLE>
<BR>
<BR>
</TD>
</TR>
<!-- END first item in the table -->
I want to extract the item details, starting with the course name (which is the text content, "linked text," inside th.ddtitle) and the course link (which is the a href inside th.ddtitle). Here's what I've tried for grabbing those two items:
$dom = new DOMDocument();
$myHtml = file_get_contents(__DIR__.'myfile.html');
$dom->loadHTML($myHtml);
$xpath = new DOMXPath($dom);
// first part changes an outer table with the same class, so I can get inner tables without the outer one
$tables = $xpath->query("//table[#class='datadisplaytable']");
for($i=0; $i<1; $i++) {
$tables[$i]->setAttribute('class', 'masterTable');
}
$html = $dom->saveHTML();
// now, the query I'm having trouble with:
$textAndLink = $xpath->query("//th[#class='ddtitle']/*");
$i=1;
foreach($textAndLink as $info) {
foreach($info->childNodes as $child) {
if($i%2 == 0) {
echo $child->getAttribute('href') . '<br>';
} else {
echo $child->nodeValue . '<br>';
}
}
$i++;
}
I've also tried print_r($child) and the only items displayed are the text nodes, no <a> tags. How can I get both the anchor's "href" attribute and the text content? What I am expecting from the code above is a list like this:
http://foo.com/<br>
Linked text<br>
http://foo.com/secondlink<br>
Second linked text<br>
and so on and so forth.
Try this code snippet here
<?php
ini_set('display_errors', 1);
$string = '
<TABLE CLASS="datadisplaytable" SUMMARY="Layout table" width="100%"><CAPTION class="captiontext">Items Found</CAPTION>
<!-- START of first item in the table -->
<TR>
<TH CLASS="ddtitle" scope="colgroup" >Linked text</TH>
</TR>
<TR>
<TD CLASS="dddefault">
<SPAN class="fieldlabeltext">Term: </SPAN>Fall
<BR>
<SPAN class="fieldlabeltext">Registration: </SPAN>Jan 1, 2018 to Aug 1, 2018
<BR>
<SPAN class="fieldlabeltext">Levels: </SPAN>Undergraduate
<BR>
<BR>
Location
<BR>
Lecture Schedule Type
<BR>
3.000 Credits
<BR>
View Entry
<BR>
<BR>
<TABLE CLASS="datadisplaytable" SUMMARY="Meeting time table"><CAPTION class="captiontext">Scheduled Meeting Times</CAPTION>
<TR>
<TH CLASS="ddheader" scope="col" >Type</TH>
<TH CLASS="ddheader" scope="col" >Time</TH>
<TH CLASS="ddheader" scope="col" >Days</TH>
<TH CLASS="ddheader" scope="col" >Where</TH>
<TH CLASS="ddheader" scope="col" >Date Range</TH>
<TH CLASS="ddheader" scope="col" >Schedule Type</TH>
<TH CLASS="ddheader" scope="col" >Instructors</TH>
</TR>
<TR>
<TD CLASS="dddefault">Lecture</TD>
<TD CLASS="dddefault">9:20 am - 10:10 am</TD>
<TD CLASS="dddefault">MWF</TD>
<TD CLASS="dddefault">Some Building Room 101</TD>
<TD CLASS="dddefault">Aug 1, 2018 - Dec 1, 2018</TD>
<TD CLASS="dddefault">Lecture</TD>
<TD CLASS="dddefault">Instructor Name (<ABBR title= "Primary">P</ABBR>)<A HREF="mailto:email#foo.com" target="Instructur Name" ><IMG SRC="/wtlgifs/email.png" ALIGN="middle" ALT="E-mail" CLASS="headerImg" TITLE="E-mail" NAME="web_email" HSPACE=0 VSPACE=0 BORDER=0 HEIGHT=16 WIDTH=16></A></TD>
</TR>
</TABLE>
<BR>
<BR>
</TD>
</TR>';
$domDocument = new DOMDocument();
$domDocument->loadHTML($string);
$domXPath = new DOMXPath($domDocument);
$results = $domXPath->query('//tr/th[#class="ddtitle"]/a');
foreach($results as $result)
{
print_r($result->textContent);
print_r($result->getAttribute("href"));
}

Time Banding with Mysql time datatype

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`
[...]

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'");

Problems scraping all data within a table

I'm having some issues getting all the data I need from two specific html tables. Tables at the bottom of this post.
The code above states html table id "table1". I also need to grab values from a table called "table2" in the exact same format. I have tried this code and can extract the td values but not the few values that are within the span specifiers within the td. I've tried multiple ways to do this but I'm just not getting it. My code looks something like:
$dom = file_get_html("internets.html);
//not sure how to specify the table exactly!? because this code didn't work.
//$tds = $dom->find('table[id=table1]',0)->find('tr');
foreach($dom->find('tr') as $key => $tr)
{
$td = $tr->find('td');
echo $td[0]->innertext . "</br>";
}
Any assistance much appreciated. I have done some searching here and also used the simple php dom manual.
Here is the format of a table:
<table id="table1">
<tbody>
<tr>
<th width="48%" scope="row">
Prev Close:
</th>
<td class="yfnc_tabledata1">
0.02
</td>
</tr>
<tr>
<th width="48%" scope="row">
Open:
</th>
<td class="yfnc_tabledata1">
0.02
</td>
</tr>
<tr>
<th width="48%" scope="row">
Bid:
</th>
<td class="yfnc_tabledata1">
<span id="yfs_b00_pgo.ax">
0.0180
</span>
</td>
</tr>
<tr>
<th width="48%" scope="row"></th>
<td class="yfnc_tabledata1"></td>
</tr>
<tr>
<th width="48%" scope="row">
1y Target Est:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
<tr>
<th width="48%" scope="row">
Beta:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
<tr>
<th width="54%" scope="row">
Next Earnings Date:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
</tbody>
</table>
<?php
$html=<<<XHTML
<table id="table1">
<tbody>
<tr>
<th width="48%" scope="row">
Prev Close:
</th>
<td class="yfnc_tabledata1">
0.02
</td>
</tr>
<tr>
<th width="48%" scope="row">
Open:
</th>
<td class="yfnc_tabledata1">
0.02
</td>
</tr>
<tr>
<th width="48%" scope="row">
Bid:
</th>
<td class="yfnc_tabledata1">
<span id="yfs_b00_pgo.ax">
0.0180
</span>
</td>
</tr>
<tr>
<th width="48%" scope="row"></th>
<td class="yfnc_tabledata1"></td>
</tr>
<tr>
<th width="48%" scope="row">
1y Target Est:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
<tr>
<th width="48%" scope="row">
Beta:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
<tr>
<th width="54%" scope="row">
Next Earnings Date:
</th>
<td class="yfnc_tabledata1">
N/A
</td>
</tr>
</tbody>
</table>
XHTML;
$dom = new DOMDocument;
$dom->loadHTML($html);
$xp = new DOMXPath($dom);
foreach ($xp->query("/*//table[#id='table1'//*/td") as $i=>$node) {
echo $node->nodeValue;
}
?>

Categories