02.
<head>
03.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=windows-874"
/>
04.
<title>Untitled Document</title>
05.
<script type=
"text/JavaScript"
>
06.
<!--
07.
function
timedRefresh(timeoutPeriod) {
08.
setTimeout(
"location.reload(true);"
,timeoutPeriod);
09.
}
10.
11.
</script>
12.
</head>
13.
14.
<body onLoad=
"JavaScript:timedRefresh(10000);"
><!-- กำหนดเวลาในการ Refresh ยิ่งเยอะยิ่งนาน -->
15.
<?php
16.
$serverName
=
"localhost"
;
17.
$userName
=
"root"
;
18.
$userPassword
=
"12345678"
;
19.
$dbName
=
"dbname"
;
20.
21.
$conn
= mysqli_connect(
$serverName
,
$userName
,
$userPassword
,
$dbName
);
22.
23.
if
(mysqli_connect_errno()) {
24.
echo
"Failed to connect to MySQL: "
. mysqli_connect_error();
25.
}
26.
27.
$depid
=
"A006"
;
28.
$aType
=
array
(
'P0'
,
'15'
,
'B0'
,
'D0'
,
'W0'
,
'D1'
,
'W1'
,
'D2'
,
'W2'
);
29.
$aCat
=
array
(1,2,3,4,5,6,7,8,9);
30.
31.
date_default_timezone_set(
'Asia/Bangkok'
);
32.
33.
$begintime1
=
strtotime
(
"12:01:01"
);
34.
$endtime1
=
strtotime
(
"12:59:00"
);
35.
36.
$begintime2
=
strtotime
(
"17:01:01"
);
37.
$endtime2
=
strtotime
(
"24:00:00"
);
38.
39.
$begintime3
=
strtotime
(
"00:00:01"
);
40.
$endtime3
=
strtotime
(
"08:59:59"
);
41.
42.
$now
= time();
43.
44.
if
((
$now
>=
$begintime1
&&
$now
<=
$endtime1
) || (
$now
>=
$begintime2
&&
$now
<=
$endtime2
) || (
$now
>=
$begintime3
&&
$now
<=
$endtime3
)) {
45.
$i
= 0;
46.
foreach
(
$aType
as
$newsType
) {
47.
48.
49.
51.
52.
libxml_use_internal_errors(true);
53.
$doc
= simplexml_load_string(
file_get_contents
(
$url
));
54.
if
(
$doc
=== false) {
55.
libxml_clear_errors();
56.
libxml_use_internal_errors(
$doc
);
57.
}
else
{
58.
$items
=
$doc
->xpath(
"/rss/channel/item"
);
59.
foreach
(
$items
as
$item
) {
60.
61.
$sql
=
"SELECT * FROM tbl_egp WHERE TRIM(egp_detail)=TRIM('"
.
$item
->link.
"') AND cat_id="
.
$aCat
[
$i
];
62.
$result
=
$conn
->query(
$sql
);
63.
$numrows
=
$conn
->num_rows;
64.
if
(!
$numrows
) {
65.
$sql
=
"INSERT INTO tbl_egp (egp_title, egp_detail, cat_id) VALUES ('"
.trim(
$item
->title).
"','"
.trim(
$item
->link).
"',"
.
$aCat
[
$i
].
")"
;
66.
$query
=
$conn
->query(
$sql
) ;
67.
}
68.
$i
++;
69.
}
70.
}
71.
}
72.
}
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
?>
87.
88.
89.
</body>
90.
</html>