PHP-based simple acquisition of data warehousing program "sequel", PHP Collection of inbound sequel _php tutorial

Source: Internet
Author: User

PHP-based simple acquisition of data warehousing program "sequel", PHP Collection and storage sequel


In the previous article, we have collected the list data of the news information page, and the next thing to do is to read the 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:

<?php    include_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>/ius"; Preg_match ($pattern, $content, $info);//get content to store info echo $title = $row [1]. "
"; 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> $id the ORDER 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 ""; }? >

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.


PHP Collection and storage problems

PHP has $NR = implode (' # ', $arr) method, you can
But above the composition is "Content 2", there is no last face of a #, if necessary
is $nr = implode (' # ', $arr). ' #'

In a stupid way, it is to use
foreach ($arr as $VL) {
$nr. = $vl. " #";
}
Reference: $

PHP Collection and storage problems

Mysql_connect ()//Connect your database First
mysql_select_db ()//Select your database
mysql_query ("INSERT into your table (address, title) VALUES (' $tmp [1][$i] ', $tmp [2][$i]);//ok, get it done!

http://www.bkjia.com/PHPjc/854355.html www.bkjia.com true http://www.bkjia.com/PHPjc/854355.html techarticle PHP-based simple acquisition of data warehousing program "sequel", PHP Collection and storage sequel in the previous article, we have collected the News information page list data, the next thing to do is from ...

  • 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.