【发布时间】:2017-05-22 20:43:21
【问题描述】:
我想知道如何将数据插入到我从其他网站提取的数据库表中
我的数据库表结构是:
mysqli_query($db, "INSERT into doctors(name, spec, qualification, image) VALUES('$name', '$spec', '$qua', '$image'));
这是我从外部提取数据的 php 代码
<?php
require('admin/inc/simple_html_dom.php');
require('admin/inc/db.php');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://health.hamariweb.com/rawalpindi/doctors",
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
));
$file = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
$dom = new simple_html_dom();
$dom->load($file);
$doctorDivs = $dom->find("#infinite-grid-images", 0)->children();
$doctors = array();
foreach($doctorDivs as $div){
$doctor = array();
$image = $doctor["image"] = "http://health.hamariweb.com".$div->find('img', 0)->src;
$details = $div->find('table', 1)->find("tr");
$name = $doctor["name"] = trim($details[0]->plaintext);
$spec = $doctor["Spec"] = trim($details[1]->plaintext);
$qua = $doctor["etc"] = trim($details[2]->plaintext);
$doctors[] = $doctor;
while($doctors){
mysqli_query($con, "INSERT into doctors(name, spec, qualification, image) VALUES('$name', '$spec', '$qua', '$image')");
}
}
echo "<pre>";
var_dump($doctors);
?>
【问题讨论】:
-
请向我们展示一些要处理的实际数据,向我们展示您的数据库表结构,向我们展示您希望看到的内容,向我们展示自我解决的尝试。