Here I am trying to get the Event Date and The name of the Event. E.g On 05/08/2018 there is FA Community Shield event, so I want to get the Event name "FA Community Shield" and the date at the same time and store it in the database at id
!date
!event_name
I am able to get the date and store it in the database, however, I am unable to store it together.
$curl = curl_init();
$url = "https://www.brent.gov.uk/events-and-whats-on-calendar/?eventCat=Wembley+Stadium+events";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result_site = curl_exec($curl);
libxml_use_internal_errors(true);
$domd=@DOMDocument::loadHTML($result_site);
// New Version // $domd = new DOMDocument();
// New Version // $domd->loadHTML( $result );
$dateElements=$domd->getElementsByTagName("article")->item(0)->getElementsByTagName("h3");
foreach($dateElements as $ele){
$data = (date("Y-m-d",strtotime($ele->textContent)));
// echo "<br>".$data;
$sql_1 = "SELECT * FROM event_table WHERE date = '$data'";
$result_site = $conn->query($sql_1);
//var_dump($result_site);
if ($result_site->num_rows > 0) {
// output data of each row
while($row = $result_site->fetch_assoc()) {
//var_dump($row);
}
}
else {
$results_1 = mysqli_query($conn, "INSERT INTO event_table (id, date, event_name) VALUES ('', '$data', '')");
}
}
$valueElements=$domd->getElementsByTagName("article")->item(0)->getElementsByTagName("a");
foreach($valueElements as $lel){
$name = $lel->textContent;
echo "<br>".$name;
$sql_2 = "SELECT * FROM event_table WHERE event_name = '$name'";
$result_site = $conn->query($sql_2);
//var_dump($result_site);
if ($result_site->num_rows > 0) {
// output data of each row
while($row = $result_site->fetch_assoc()) {
//var_dump($row);
}
}
else {
$results_1 = mysqli_query($conn, "INSERT INTO event_table (id, date, event_name) VALUES ('', '', '$name')");
}
}
$conn->close();
?>
Aucun commentaire:
Enregistrer un commentaire