Data warehousing program based on PHP acquisition (II.)

Source: Internet
Author: User

In the previous article based on the PHP Data Warehousing Program (ii) mentions the collection of news information page list data, next talk about the collection of news specific content

This is the final data sheet for the previous blog:

The next thing to do is to read the required URL from the database and fetch the page.

Create a new content table

However, it is important to note that the acquisition URL can no longer be used to collect the ID increment, because the data table may appear in the ID discontinuity, such as id=9,id=11, when the acquisition of id=10, the URL is blank, which may lead to the acquisition of empty fields.

One of the techniques used here is the database query statement, when we collect the first data, determine whether there is more than this ID ID number in the database, if so, read a, query information duplication above the work.

The specific code is as follows:

<?PHPinclude_once("conn.php"); $id= (int)$_get[' ID ']; $sql= "SELECT * FROM list where id=$id"; $result=mysql_query($sql); $row=Mysql_fetch_array($result);//get the corresponding URL address    $content=file_get_contents($row[' URL ']); $pattern= "/<dd class=\" Datawrap\ "> (. *) <\/dd>/ius"; Preg_match($pattern,$content,$info);//Get content Store Info    Echo $title=$row[1]. " <br/> "; Echo $content=$info[0]. " ; //Insert Database    $add= "INSERT into content (title,content) value ('$title‘,‘$content‘)"; mysql_query($add); $sql 2= "SELECT * FROM list where id>$idORDER BY ID ASC limit 1 "; $result 2=mysql_query($sql 2); $row 2=Mysql_fetch_array($result 2);//get the corresponding URL address    if($row 2[' ID ']){        Echo"<script>window.location= ' content.php?id=$row 2[0] ' </script> '; }?>

This is what we want to the news content is collected into the storage, the next only need to sort out some of the data style to organize the line.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.