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.