ZENCART php randomly calls the title and content of the database

Source: Internet
Author: User

ZENCART php randomly calls the title and content of the database


Using the program to work with SEO is a good idea. Using the PHP code, you can use the articles and standard content in the data library on your phone, when refreshing the front-end interface, different content is displayed. If the spider can capture different contents every time it crawls, is the effect good.

So I just copied onePHP appletsTo realize this function. The principle is as follows:

First, I create a table named randcontent in the Data Warehouse. Then, the table contains three fields: post_id, post_title, post_content, then, use the phone number to retrieve a post_id, and then use the post_id to retrieve the content of post_title and post_content.

  1. $ Dbh = @ mysql_connect ("localhost", "root ","");

  2. If (! $ Dbh) {die ("error ");}

  3. @ Mysql_select_db ("phptest", $ dbh );

  4. $ Posttotal = "select count (post_id) as total FROM randcontent WHERE post_id is not null"; // SQL statement, which reads the number of rows in the table

  5. $ Query1 = mysql_query ($ posttotal, $ dbh); // begin an SQL statement.

  6. $ Res = mysql_fetch_array ($ query1); // generate a Data Group

  7. $ Count = $ res ['Total']; // change the memory value to $ count

  8. $ Randcount = rand (1, $ count); // gets a number between ID1 and the maximum number of articles on the fly. This number is the ID of this article.

  9. $ Getpost = "SELECT post_title, post_content FROM randcontent WHERE post_id = $ randcount ";

  10. $ Query2 = mysql_query ($ getpost, $ dbh );

  11. $ Res2 = mysql_fetch_array ($ query2); // generate a Data Group

  12. $ Post_title = $ res2 ['Post _ title']; // obtain the subject

  13. $ Post_content = $ res2 ['Post _ content']; // retrieve the content

  14. Echo '<strong>'. $ post_title. '</strong> <br/>'. $ post_content; // specify the subject and content.


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.